[SalesForce] LWC counterpart to Aura’s force:createRecord event

My Aura component use the force:createRecord event to display an prepopulated new record page. What is the counterpart in #LWC?

There is a createRecord thing but it does different things.

Best Answer

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.