1

I am creating a Lightning Component (Aura) to create a child record from the parent record. The basic component worked up until I added the "recordId="{!v.recordId}"" line after <lightning:recordEditForm. I just get an error message now that says [object object]. Can anyone spot what I have wrong here?

The parent object is "Employee__c" and the child object is "Employee_Session__c".

<aura:component implements="flexipage:availableForRecordHome,force:hasRecordId,force:lightningQuickAction" access="global" >
    <aura:attribute name="disabled" type="Boolean" default="false" />
    <aura:attribute name="saved" type="Boolean" default="false" />
    <aura:attribute name="showSpinner" type="Boolean" default="true" />
    <aura:attribute name="recordId" type="String" />
    <aura:if isTrue="{!v.showSpinner}">
        <lightning:spinner />
    </aura:if>
    <aura:if isTrue="{!!v.saved}">
        <lightning:recordEditForm
            recordId="{!v.recordId}"
            onload="{!c.handleLoad}"
            onsubmit="{!c.handleSubmit}"
            onsuccess="{!c.handleSuccess}"
            objectApiName="Employee_Session__c"
            >
            <!-- the messages component is for error messages -->
            <lightning:messages />
            <lightning:inputField fieldName="Name" />
            <lightning:inputField fieldName="Employee__c" value="{!v.recordId}" />
            <lightning:inputField fieldName="Intro_with_Compliance_Verbiage__c" />
            <lightning:inputField fieldName="Core__c" />
            <lightning:inputField fieldName="Voluntary_Benefits__c" />
            <lightning:inputField fieldName="Conclusion__c" />
            <div class="slds-m-top_medium">
                <lightning:button disabled="{!v.disabled}" variant="brand" type="submit" name="save" label="Create Session" />
            </div>
        </lightning:recordEditForm>
        <aura:set attribute="else">
            <p>Saved! New record id is {!v.recordId}</p>
        </aura:set>
    </aura:if>
</aura:component>

enter image description here

  • why you parent v.recordid added in` recordId="{!v.recordId}"` for child record form lightning:recordEditForm , what is your use case? that's why cmp gets confused because your parent component implemented by force:hasRecordId – sdandamud1 Jun 21 '19 at 21:23
0

The issue is you are trying to create a record of the child object i.e. Employee_Session__c and passing the record id of your parent object Employee__c to your form as recordId attribute will have the current record id.

<lightning:recordEditForm
            recordId="{!v.recordId}"
            onload="{!c.handleLoad}"
            onsubmit="{!c.handleSubmit}"
            onsuccess="{!c.handleSuccess}"
            objectApiName="Employee_Session__c"
            >

As you are creating a record, you don't need the recordId attribute in your form markup definition. your markup should be like this:-

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

Read more here:- Aura Component Record Edit Form

| improve this answer | |

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.