The purpose of this blog is to share you detail how to load Create child Record using Standard Layout using Lightning Action Button.
Here are the Relationship with Objects.
We are using following 3 Objects:
1. Account
2. Project
3. Invoice
Invoice has following relationship fields:
Account --Master -Detail
Project --Lookup
Project has following relationship fields:
Account--Lookup
So User can create Invoice Records from Project's Invoice Related list so while clicking on New Invoice button Project Lookup is filled but Account lookup is not autofilled. So in order to Create Invoice from Project and that new Invoice Record Layout must be defaulted with Project, Account and other detal from Project Record we will be create one Lightning Action button Project Object with following Lightning component. so without creating any server side apex controller we can use lightning data service to Read the records and then we can invoke the CreateRecord lightning enque action in JS. rest Salesforce will take care of it.
Please create following component.
CreateInvoice.cmp
<aura:component implements="force:lightningQuickActionWithoutHeader,force:hasRecordId" access="global" >
<aura:attribute name="project" type="Project_Custom__c"/>
<aura:attribute name="projectObj" type="Project_Custom__c"/>
<aura:attribute name="errorMessage" type="String"/>
<force:recordData aura:id="accountRecordLoader"
recordId="{!v.recordId}"
fields="Customer__c,CurrencyIsoCode"
targetRecord="{!v.project}"
targetFields="{!v.projectObj}"
targetError="{!v.errorMessage}"
recordUpdated="{!c.doInit}"
/>
</aura:component>
CreaInvoiceController.js
({
doInit : function(component, event, helper) {
$A.get("e.force:closeQuickAction").fire();
var eventParams = event.getParams();
if(eventParams.changeType === "LOADED") {
//console.log("account loaded:::::" + JSON.stringify(component.get("v.project")));
var createRecordEvent = $A.get("e.force:createRecord");
createRecordEvent.setParams({
"entityApiName": "Invoice__c",
"defaultFieldValues":{
"Account__c" : component.get("v.projectObj.Customer__c"),
"CurrencyIsoCode" : component.get("v.projectObj.CurrencyIsoCode"),
"Project__c" : component.get("v.recordId")
}
});
createRecordEvent.fire();
} else if(eventParams.changeType === "REMOVED") {
// record is deleted and removed from the cache
} else if(eventParams.changeType === "ERROR") {
// there’s an error while loading, saving or deleting the record
}
}
})
Create Lightning Action button on Project and select the component that you above has defined. and enable this new button on the Project Page Layout. Thanks
Here are the Relationship with Objects.
We are using following 3 Objects:
1. Account
2. Project
3. Invoice
Invoice has following relationship fields:
Account --Master -Detail
Project --Lookup
Project has following relationship fields:
Account--Lookup
So User can create Invoice Records from Project's Invoice Related list so while clicking on New Invoice button Project Lookup is filled but Account lookup is not autofilled. So in order to Create Invoice from Project and that new Invoice Record Layout must be defaulted with Project, Account and other detal from Project Record we will be create one Lightning Action button Project Object with following Lightning component. so without creating any server side apex controller we can use lightning data service to Read the records and then we can invoke the CreateRecord lightning enque action in JS. rest Salesforce will take care of it.
Please create following component.
CreateInvoice.cmp
<aura:component implements="force:lightningQuickActionWithoutHeader,force:hasRecordId" access="global" >
<aura:attribute name="project" type="Project_Custom__c"/>
<aura:attribute name="projectObj" type="Project_Custom__c"/>
<aura:attribute name="errorMessage" type="String"/>
<force:recordData aura:id="accountRecordLoader"
recordId="{!v.recordId}"
fields="Customer__c,CurrencyIsoCode"
targetRecord="{!v.project}"
targetFields="{!v.projectObj}"
targetError="{!v.errorMessage}"
recordUpdated="{!c.doInit}"
/>
</aura:component>
CreaInvoiceController.js
({
doInit : function(component, event, helper) {
$A.get("e.force:closeQuickAction").fire();
var eventParams = event.getParams();
if(eventParams.changeType === "LOADED") {
//console.log("account loaded:::::" + JSON.stringify(component.get("v.project")));
var createRecordEvent = $A.get("e.force:createRecord");
createRecordEvent.setParams({
"entityApiName": "Invoice__c",
"defaultFieldValues":{
"Account__c" : component.get("v.projectObj.Customer__c"),
"CurrencyIsoCode" : component.get("v.projectObj.CurrencyIsoCode"),
"Project__c" : component.get("v.recordId")
}
});
createRecordEvent.fire();
} else if(eventParams.changeType === "REMOVED") {
// record is deleted and removed from the cache
} else if(eventParams.changeType === "ERROR") {
// there’s an error while loading, saving or deleting the record
}
}
})
Create Lightning Action button on Project and select the component that you above has defined. and enable this new button on the Project Page Layout. Thanks
9 Comments
Hi nice post about Creating a Salesforce Lightning and its a good article but you missed some important topics which i covered in my blog about salesforce intigrations https://cloudanalogy.com/blog/nodejs-salesforce-integration-drives-enhanced-employee-engagement-telmatics/
ReplyDeleteNice solution. i aslo write Salesforce related content please check https://cloudanalogy.com/blog
ReplyDeleteGood Post. I like your blog. Thanks for Sharing
ReplyDeleteSalesforce Course in Delhi
Apex legends founders pack
ReplyDeleteThe best place to buy Apex Legends Founders Pack Key - www.scdkey.com, we can provide you Official and Legit cheap Apex Legends Founders Pack with instant delivery. Come and Enjoy!
to get more - https://www.scdkey.com/apex-legends-founders-pack-cloud-activation-key-global_2972-20.html
Thank you for your tutorials on Salesforce. I too have a passion for teaching and have also created courses in field of Salesforce Administration and Development. I have a great opportunity for you if you are interested. Would you like to be an affiliate partner for us? We will love to share 50% commission on every sale through your website.You can reach out to me at +1-469-408-6808. Here is the link to our website: https://mytutorialrack.com/
ReplyDeleteI really enjoyed while reading your article and it is good to know the latest updates. Do post more. Please also read my topics about
ReplyDeleteSalesforce Blog
Export Process Builders in Salesforce
Blog posts very informative and useful
ReplyDeleteBest Play and Pre School for kids in Hyderabad,India. To give your kid a best environment and learning it is the right way to join in play and pre school were kids can build there physically, emotionally and mentally skills developed. We provide programs to kids like Play Group, Nursery, Sanjary Junior, Sanjary Senior and Teacher training Program.
Preschool in hyderabad
Hiiii....Thanks for sharing Great Information...Keep move on....
ReplyDeleteBest Salesforce Training Institutes in Hyderabad
Thank you for introducing this tool. keep it updated.
ReplyDeleteLearn Salesforce CPQ
Salesforce CPQ Online Training