0

I am creating a new lightning component to use as a new Factfind area.

I have a lookup field on the backend that links to opportunity and I am displaying this using an lightning:inputField.

However when I try to assign it a value so it is already populated it does nothing.

I need it to pull the id from the opportunity that you create the new record on.

Here is my component where the code is referenced, any help would be greatly appreciated :)

<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes,force:hasRecordId,force:lightningQuickActionWithoutHeader,flexipage:availableForRecordHome,lightning:actionOverride" 
            access="global" >

<aura:attribute name="selTabId" type="string" default="Objective" />

<lightning:navigation aura:id="navService"/>

<lightning:recordEditForm objectApiName="Factfind__c"
                          recordId="{!v.recordId}"
                          onsubmit="{!c.handleSubmit}"
                          onsuccess="{!c.handleSuccess}">
    <lightning:messages />
    <lightning:tabset selectedTabId="{!v.selTabId}" variant="vertical">
        <lightning:tab label="Objectives" id="Objective">

            <h2>TFC Section</h2>

        <div style="width: 50%; padding: 14px;">                

            <lightning:inputField fieldName="Opportunity__c" value="{!v.recordId}"/> 
            <p/><br/>
2
  • No need to assign any value to it the recordEditForm will do that. – itzmukeshy7 Aug 15 '19 at 14:50
  • sadly it does not populate the lookup field on clicking the new button haha – JackDower Aug 15 '19 at 15:24
1

You are using the "v.recordId" in two places. One in the lightning:recordEditForm definition and other for the Opportunity__c field. That is incorrect. If you are invoking this action from an Opportunity then your v.recordId would be the Opportunity Id and if you are invoking this action from a record of type Factfind__c then the v.recordId in the Factfind__c record id.

I assume in your case you are trying to create a new Factfind__c record from the lightning component on the Opportunity. In that case, you should not add the recordId attribute to the lightning:recordEditForm.

Please try,

<lightning:recordEditForm objectApiName="Factfind__c"
                          onsubmit="{!c.handleSubmit}"
                          onsuccess="{!c.handleSuccess}">

If your scenario is something different please let me know.

Here is my lightning component example for creating a contact from an Account. I added this component as a Quick action on the Account layout

<aura:component implements="force:lightningQuickAction,force:hasRecordId">

    <h3 style="font-weight:bold">New Contact:</h3>

    <lightning:recordEditForm objectApiName="Contact"
                          onsubmit="{!c.handleSubmit}"
                          onsuccess="{!c.handleSuccess}">
        <lightning:inputField fieldName="Email" aura:id="ct_email"/>
        <lightning:inputField fieldName="AccountId" value="{!v.recordId}"/>

    </lightning:recordEditForm>

</aura:component>
1
  • Hiya dude, Thankyou for this helped me out loads, I had it set up running from a button and then in its own page so i think this was causing part of this issue aswell but now doing it as a quick action with some css code around it so the modal box is bigger it works perfect! – JackDower Aug 16 '19 at 8:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.