You need to sign in to do that
Don't have an account?
Bryan Leaman 6
Can I use lightning:recordEditForm to create a related record?
I have a lightning component using force:hasRecordId. What I've been trying to do (unsuccessfully) is have a subform that just needs one lookup field and automatically fill in the current parent object's record Id and write the new related record.
The problem is the fields don't even render. Hidden in the html is
<span class="slds-hide">
"No input rendered: "
"Field "undefined" not found in response."
</span>
I've used lightning:recordeditform before, but only to create & update the object record who's page I'm on, not a related list record.
I'm getting the main record's data using force:recordData (this works fine):
<force:recordData aura:id="dealEditor"
recordId="{!v.recordId}"
fields="Id,Name"
targetFields="{!v.dealFields}"
targetError="{!v.dealError}"
recordUpdated="{!c.dealHandleRecordUpdated}"
mode="EDIT"
/>
On successful load of the force:recordData I'm setting the new credit application's Proposal__c field so the new record will be properly linked:
component.find("newca_proposal").set("v.value", component.get("v.dealFields.Id"));
And I want to allow lookup of one field and then write a related record:
<aura:attribute name="newCreditAppId" type="String"/>
<lightning:recordEditForm aura:id="newcreditapp"
recordId="{!v.newCreditAppId}"
objectApiName="dealer__Credit_Application__c"
onsubmit="{!c.newCreditAppSave}"
class="slds-card__body_inner"
>
<lightning:inputField fieldname="Finance_Company__c" aura:id="newca_financecompany"/>
<lightning:inputField fieldname="Proposal__c" aura:id="newca_proposal"/>
<lightning:button type="submit" label="Add Finance Company"/>
</lightning:recordEditForm>
Is this possible? What am I missing?
The problem is the fields don't even render. Hidden in the html is
<span class="slds-hide">
"No input rendered: "
"Field "undefined" not found in response."
</span>
I've used lightning:recordeditform before, but only to create & update the object record who's page I'm on, not a related list record.
I'm getting the main record's data using force:recordData (this works fine):
<force:recordData aura:id="dealEditor"
recordId="{!v.recordId}"
fields="Id,Name"
targetFields="{!v.dealFields}"
targetError="{!v.dealError}"
recordUpdated="{!c.dealHandleRecordUpdated}"
mode="EDIT"
/>
On successful load of the force:recordData I'm setting the new credit application's Proposal__c field so the new record will be properly linked:
component.find("newca_proposal").set("v.value", component.get("v.dealFields.Id"));
And I want to allow lookup of one field and then write a related record:
<aura:attribute name="newCreditAppId" type="String"/>
<lightning:recordEditForm aura:id="newcreditapp"
recordId="{!v.newCreditAppId}"
objectApiName="dealer__Credit_Application__c"
onsubmit="{!c.newCreditAppSave}"
class="slds-card__body_inner"
>
<lightning:inputField fieldname="Finance_Company__c" aura:id="newca_financecompany"/>
<lightning:inputField fieldname="Proposal__c" aura:id="newca_proposal"/>
<lightning:button type="submit" label="Add Finance Company"/>
</lightning:recordEditForm>
Is this possible? What am I missing?
All Answers
Do it like this
https://developer.salesforce.com/docs/component-library/bundle/lightning:recordEditForm/example#lightningcomponentdemo:exampleRecordCreate
Try the Onload function in <lightning:recordEditForm> maybe that will Prepopulate your Id in the Lookupfield.
Like Below:
<lightning:recordEditForm aura:id="newcreditapp"
recordId="{!v.newCreditAppId}"
objectApiName="dealer__Credit_Application__c"
onsubmit="{!c.newCreditAppSave}"
onload="{!c.handleOnload}"
class="slds-card__body_inner">
In JS Controller :
handleOnload : function(component, event, helper) {
// Here am using the Force:hasRecordId interface itself for setting the value if you want you can change. Because i hope you can get the parent ID from component.get("v.recordId") .
component.find("newca_proposal").set("v.value", component.get("v.recordId"));
// component.find("newca_proposal").set("v.value", component.get("v.dealFields.Id"));
}
Can you please Let me know if it helps or not!!!
If it helps don't forget to mark this as a best answer!!!
Thanks,
Maharajan.C
Maharajan.C, The problem isn't that the value is not populating. The problem is my fields don't even render on the screen. If I don't try to fill in the lookup value I still don't get a field on the screen to manually select the value.