You need to sign in to do that
Don't have an account?
Julien Salenson
lightning:recordeditform is not populating lookup fields
Hi,
I have created this component :
Where Sales_DT__c is a lookup on User.
This field Sales_DT__c has a value recorded : 00530000004FGcfAAG.
Before, it's was working with this old workaround : add lightning:recordViewForm in the same compoent, but it's doesn't work anymore :
I have already read this : https://developer.salesforce.com/forums#!/feedtype=SINGLE_QUESTION_SEARCH_RESULT&id=9060G0000005qTaQAI
But, I didn't found a good response.
Any idea on how to populating this lookup field when I load the component ?
I have created this component :
<lightning:recordEditForm aura:id="edit" recordId="{!v.recordId}" objectApiName="Account" > <lightning:inputField fieldName="Sales_DT__c" variant="label-hidden"/> </lightning:recordEditForm>
Where Sales_DT__c is a lookup on User.
This field Sales_DT__c has a value recorded : 00530000004FGcfAAG.
Before, it's was working with this old workaround : add lightning:recordViewForm in the same compoent, but it's doesn't work anymore :
<lightning:recordViewForm recordId="{!v.recordId}" objectApiName="Account" > <div class="slds-hidden"> <lightning:outputField fieldName="Sales_DT__c" /> </div> </lightning:recordViewForm>
I have already read this : https://developer.salesforce.com/forums#!/feedtype=SINGLE_QUESTION_SEARCH_RESULT&id=9060G0000005qTaQAI
But, I didn't found a good response.
Any idea on how to populating this lookup field when I load the component ?
You can find complete code here: https://newstechnologystuff.com/2018/10/06/lightningrecordeditform-save-data-without-apex/
If this answer helps you, please mark it as accepted.
Regards,
Tushar Sharma
https://newstechnologystuff.com/
But how to populate it with his current value (instead of 'Tushar Sharma') ?
Thank you
I have contacted SF support and they gave me 2 workarounds :
1)For the lookup field to be populated from lightning:recordEditform, the field MUST first be included in the page layout of the object.
2) If you don't want to add it in the page layout, well it's a know issue :
https://help.salesforce.com/articleView?id=000349125&language=en_US&type=1&mode=1
Below is the sample code i they gave me created and I tested it :
Lightning Component :
----------------------------------
Controller :
-----------------
Apex controller :
------------------------
Notes :
>> I have created a lookup field "Payments__c" on Account object , which refers to custom object "Payments__c".
>> On the lightning component you can see in the lightning:recordEditForm form you have an aura:id on payments field.
>> On the Client Controller in method onLoad , we call an apex controller to get the values of the lookup fields and populate them to the respective fields using aura:id.
>> onLoad function is called from onload attribute call of lightning:recordEditForm (i.e handleLoad method).