function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
imrohitimrohit 

How to autopopulate Account in lightning Record Form

Hi guys, I have one lightning record form which I am using to create new contact after overriding the contact's New button code below

<aura:component implements="lightning:actionOverride,force:hasRecordId"  access="global" >
    
    <aura:attribute name="fields"
                    type="String[]"
                    default="['FirstName', 'LastName','AccountId']"/>

    <lightning:card iconName="custom:custom19" title="lightning:recordForm">
        <div class="slds-p-left_large slds-p-right_medium">	
            
    <!-- Displays toast notifications -->
    
            <lightning:recordForm
                                  objectApiName="Contact"
                                  fields="{!v.fields}"
                                  />
        </div>
    </lightning:card>
</aura:component>


now I want whenever I create New contact from Account's related list the account should be auto-populated.
how can I do this please help

 User-added image when you click on the new contact from account's related list I want account as auto-populated
User-added image

I want output as this 

User-added imageThanks in advance

Arun MohanArun Mohan
Hi Likesh,

Create a new VF page and pass the account id via url to VF page.

Refer the below link for reference to pass the value from button to VF page:
https://developer.salesforce.com/forums/?id=9060G0000005gBHQAY

refer below link to pass value from vf page to lightning component:
https://salesforce.stackexchange.com/questions/100913/how-to-pass-parameters-for-lightning-component-called-via-quick-a-action

Then use the lightning component in the VF page, so that you can achieve the requirement.

Thanks
Arun
Deepali KulshresthaDeepali Kulshrestha
Hi Likesh,
 
Add the force:hasRecordId interface to a Lightning component to enable the component to be assigned the ID of the current record. 
This will give you the Id of the record that you are viewing. With this Id you can use Apex/Record Data to load the fields that you want and put it to the component.

You can check this link,it will help you:

https://developer.salesforce.com/docs/component-library/bundle/force:hasRecordId/documentation

https://salesforce.stackexchange.com/questions/236094/how-to-auto-populate-fields-using-data-from-record-in-edit-form-using-lightning

I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.

 Thanks and Regards,
 Deepali Kulshrestha