LWC counterpart to Aura's force:createRecord event
In the new salesforce release Spring'20, we have this privilege to set the predefined values. We can now make the field API names and their values as a string and pass it to pageReference.state.defaultFieldValues attribute on standard__objectPage page reference types.
You can have the look here - https://releasenotes.docs.salesforce.com/en-us/spring20/release-notes/rn_lc_navigate_to_record_dfv.htm
For instance -
import { LightningElement } from 'lwc';
import { NavigationMixin } from 'lightning/navigation';
export default class Demo extends NavigationMixin(LightningElement) {
handleClick(){
let temp = {
type: 'standard__objectPage',
attributes: {
objectApiName: 'Account',
actionName: 'new'
},
state : {
nooverride: '1',
defaultFieldValues:"Name=Salesforce,AccountNumber=A1,AnnualRevenue=37000,Phone=7055617159"
}
};
this[NavigationMixin.Navigate](temp);
}
}
Note - Spring'20 is only available for sandboxes for now.
To construct a custom button or link that launches a new record with prepopulated field values, use this sample formula:
/lightning/o/Account/new?defaultFieldValues=
Name={!URLENCODE(Account.Name)},
OwnerId={!Account.OwnerId},
AccountNumber={!Account.AccountNumber},
NumberOfEmployees=35000,
CustomCheckbox__c={!IF(Account.SomeCheckbox__c, true, false)}
Release Notes: https://releasenotes.docs.salesforce.com/en-us/spring20/release-notes/rn_general_lex_navigate_to_record_dfv.htm