I have a custom object AP_Customer_Address__c
which has a lookup relationship to Contact
. I have an LWC on the contact record page which allows the creation of a new address for that contact. I use NavigationMixin.Navigate
to create new address records. When I try to create an address, it asks me to select a contact. I want the contact to be auto-filled and read-only. I tried adding the contact's record Id
in state
and attributes
, but it's not working.
Please guide. Thanks!
Auto Fill contact name using Contact ID
Code
this[NavigationMixin.Navigate]({
type: 'standard__objectPage',
attributes: {
recordId: this.recordId, //added record Id here
objectApiName: 'AP_Customer_Address__c',
actionName: 'new'
},
state: {
recordId: this.recordId //added record Id here
}
});
Best Answer
Pre-population is yet not supported in Lightning Web component yet for NavigationMixin functionality. I have raised an issue and an idea a long back. Yet it has not been delivered.
You need to look for other workarounds like using Aura component or Lightning Data Service to open a record form with pre-populated values.
Currently, LWC allows you to just set the recordtype value by default as of now.
Update
In spring 20, this feature has been delivered by Salesforce.
See this link. According to it, We can do this as follow:-