0

I'm writing a LWC component to open a new opportunity with some pre-filled data. However, it does not seem to matter what record type Id I pass to the default values, the page always fires up with the default record type assigned to my profile. I have stepped through the code and confirmed that a valid Id is being passed, checked that there are no overrides and reviewed the debug logs to see if something odd is happening there but have found nothing. The other prefills (abbreviated here for brevity) work without any issues, has anyone experienced this problem before?

 const defaultValues = encodeDefaultFieldValues({
     RecordTypeId: this.recordTypeId,
     StageName: "New",
     Name: "Oppo123"
 });
 
 this[NavigationMixin.Navigate]({
     type: 'standard__objectPage',
     attributes: {
         objectApiName: 'Opportunity',
         actionName: 'new'
     },
     state: {
         defaultFieldValues: defaultValues
     }
 });

1 Answer 1

2

As per the suggestion from Zakeer in the following similar question, Lightning Web Components: navigate to the 'new' object page passing in specific record type Id?:

Don't add the record type to your default values object. Instead, pass it into the state object, i.e

 const defaultValues = encodeDefaultFieldValues({
     StageName: "New",
     Name: "Oppo123"
 });
 
 this[NavigationMixin.Navigate]({
     type: 'standard__objectPage',
     attributes: {
         objectApiName: 'Opportunity',
         actionName: 'new'
     },
     state: {
         defaultFieldValues: defaultValues,
         recordTypeId: this.recordTypeId
     }
 });

The property labels are case sensitive, so, make sure you use recordTypeId and not RecordTypeId!

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .