1

I have a scenario where I am using Navigation Mixin to create a new record. So during the creation of the new record I want to prepopulate the Lookup record Id in it. But even though I configure the Lookup record Id in the Navigation Mixin, while creating a new record, it is not showing/ picking up the Lookup record Id in it.

Note: My Lookup Record belongs to the standard object and not the custom object.

Also, the only solution I thought is to create a formula field to get the associated record Id and update it using record triggered flow in the backend.

Any thoughts??

My Navigation Mixin JS code to create a new record.

  this[NavigationMixin.Navigate]({
        type: 'standard__objectPage',
        attributes: {
            objectApiName : ContactPointAddress,
            actionName: 'new'
        },
        state: {
            ParentId: this.accountId 
       }
    });

Note: I am trying to create a new Contact Point Address record with Parent (Lookup to Account) in it.

Object Reference: https://developer.salesforce.com/docs/atlas.en-us.object_reference.meta/object_reference/sforce_api_objects_contactpointaddress.htm

3
  • Please add all relevant code (in particular Javascript, but better also the formula field) to your question. This will make it much more likely that someone can solve this issue. Commented May 18 at 12:04
  • A master-detail relationship requires the ID before the DML operation starts, otherwise you will get an error. A record-triggered flow of any type is too late to set the ID. As Felix says, please provide the JavaScript you're using to start the new record dialog. You can edit your question to include the JavaScript.
    – sfdcfox
    Commented May 18 at 14:23
  • @sfdcfox Apologies. I have added the code snippet to my question. Also, when I look at the ParentId relationship in my Salesforce org, it says it is having Master Detail relationship with Account/ Individual. But the documentation says it is a lookup relationship. Thanks!
    – Loki_72
    Commented May 18 at 17:46

1 Answer 1

0

This is outlined in Navigate to a Record’s Create Page with Default Field Values. You need to use defaultFieldValues, as follows:

import { LightningElement, api } from "lwc";
import { NavigationMixin } from "lightning/navigation";
import { encodeDefaultFieldValues } from "lightning/pageReferenceUtils";

export default class MyComponent extends NavigationMixin(LightningElement) {
  @api accountId;
  hanleNavigation() {
    const defaultValues = encodeDefaultFieldValues({
      ParentId: this.accountId
    });
    this[NavigationMixin.Navigate]({
      type: "standard__objectPage",
      attributes: {
        objectApiName: "ContactPointAddress",
        actionName: "new",
      },
      state: {
        defaultFieldValues: defaultValues,
      },
    });
  }
}

You must log in to answer this question.

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