-1

The New standard button in the Salesforce is overriden by the Lightning component (Aura). Now this New button is being used in the multiple places:

  1. While creating a contact record from the list view of contacts: New button in the list view

  2. Creating a contact from the Account related list: Create Contact from the Account

In #2, I want the Account lookup field to be populated automatically when clicking on the NEW button. Below is the form that I have built using Lightning component.

My question is that - How do we identify the page where this contact button is getting clicked? With the help of the page reference or if I get the RecordId where the button is clicked, I can populate the Acccount field in the component.

I tried using the document.referrer but that is not serving me with the intended results that I need.

1 Answer 1

1

variables need to be append with c__ to use it on aura cmp.
You can create List Button with Contenr Source URL & pass accountId variable as below:

/lightning/cmp/c__AuraCMPNameHere?c__accountId={!Account.Id}
(Note. Don't add any url function or quotes in above button url)

Now in your Aura Cmp js file you've add doint function which will run when cmp loads & take variable values from pageRef state.

AuraCMPNameHere.cmp
<aura:component implements="flexipage:availableForAllPageTypes,force:hasRecordId,lightning:actionOverride,lightning:isUrlAddressable" access="global" description="some description here">
    <aura:handler name="init" action="{!c.doInit}" value="{!this}"/>
    <!--
        //cmps
    -->
</aura:component>


AuraCMPNameHere.js
({
    doInit: function(component, event, helper){
        var myPageRef = component.get("v.pageReference");
        var accountId = myPageRef.state.c__accountId;
        //do something with your accountId variable
    }
})

Now you can assign this accountId variable as per your requirement.

You must log in to answer this question.

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