function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Mohan Reddy 80Mohan Reddy 80 

how to navigate to record create page with default values from parent record using navigation

How to navigate to record create page with default field values.
e.g. contact create page qith default account id and any other lookup fields(from lookup field in account to lookup field in contact) using lightning:navigation
Santosh Kumar 348Santosh Kumar 348
You can use something like this in your component just use a method to wrap this code up and instead of contact use your object:
 
var createAcountContactEvent = $A.get("e.force:createRecord");
createAcountContactEvent.setParams({
    "entityApiName": "Contact",
    "defaultFieldValues": {
        'Phone' : '415-240-6590',
        'AccountId' : '001xxxxxxxxxxxxxxx'
    }
});
createAcountContactEvent.fire();

Do let me know if it helps you and close your query by marking it as solved.

Regards,
Santosh
Mohan Reddy 80Mohan Reddy 80
Hi Santosh,

Thanks for the reply. I want to populate lookup field with out hardcoding the record id.
Santosh Kumar 348Santosh Kumar 348
This is just an example replace the hardcoded value with the attribute where you are holding the id.
 
var recId = component.get("v.YourAttributeName");

var createAcountContactEvent = $A.get("e.force:createRecord");
createAcountContactEvent.setParams({
    "entityApiName": "Contact",
    "defaultFieldValues": {
        'Phone' : '415-240-6590',
        'AccountId' : recId
    }
});
createAcountContactEvent.fire();

Just fetch the id from the variable wherever you are storing in recId and the code will work for you.

 
Santosh Kumar 348Santosh Kumar 348
Hi Mohan,

If it has helped you mark the answer, so that it will help others as well.

Regards,
Santosh