2

I am trying to use lightning:recordEditForm to add a record to the Contact object but cannot.

I use the code as given in the documentation:

<aura:component>
    <lightning:recordEditForm aura:id="recordEditForm" 
                              objectApiName="Contact"
                              recordTypeId="0121A000000QdysQAC">
        <lightning:messages />
        <lightning:inputField fieldName="Name" />
        <lightning:button class="slds-m-top_small" type="submit" label="Create new" />
    </lightning:recordEditForm>
</aura:component>

but always get an error:

This page has an error. You might just need to refresh it. [Cannot read property 'fields' of undefined]

enter image description here

When I add the recordId attribute - this tells the component that it is in edit mode, and that works OK:

<aura:component>
    <lightning:recordEditForm aura:id="recordEditForm" 
                              objectApiName="Contact"
                              recordId="003W000000abJXIIA2"
                              recordTypeId="0121A000000QdysQAC">
        <lightning:messages />
        <lightning:inputField fieldName="Name" />
        <lightning:button class="slds-m-top_small" type="submit" label="Create new" />
    </lightning:recordEditForm>
</aura:component>

enter image description here

QUESTION

Am I missing something?

Is there anything else to do to make use of this component to add a record?

0

Place the field on the contact's layout. That did it for me. It's probably a bug in the component.

  • What do you mean? I am inside a lightning component. which contact layout are you talking about? – Itai Shmida Jan 31 '18 at 13:07
  • When you go to object manager, is the tradional page layout, where you drag and drop fields in the page that is the detail tab in lightning, if you have compulsory fields that are hidden from the page layout the component will give you issues. – manza Nov 1 '18 at 22:36
0

I haven't tried it Yet. However, to edit a record, You must need to provide the record Id. As recordId is the not required attribute for the component (recordEditForm), meaning You can get in context record by putting your component in the related object record page. Don't forget to use force:hasRecordId interface to get the recordId.

  • I do not understand how your answer relate to my question - see in my question that I have the recordId filled, and my question is about adding a record and not editing one... – Itai Shmida Feb 5 '18 at 9:21
0

This works ok for me except that I notice that the recordtype is not working 100%. It doesn't create the records in the right recordtype for me if I don't specifically include the recordtypeid field on the editform.

Maybe you can try and see what happens if you either leave out the recordtypeid tag or include the recordtypeid edit field on the form, like this:

<lightning:recordEditForm aura:id="recordCreateForm" 
                       objectApiName="Contact"
                       recordTypeId="0120Y000000aXXXXXX">
    <lightning:messages />
    <lightning:inputField fieldName="Name" />
    <lightning:inputField fieldName="RecordTypeId" />
    <lightning:button class="slds-m-top_small" type="submit" label="Create new" />
</lightning:recordEditForm>

And are you 100% sure that the recordtypeid is correct and is a recordtype of Contact and not some other object?

0

Are you running the component from the Lightning App? If yes try putting it in record page and see the behavior, i was getting similar error on using the component in Lightning App but when i placed the Light Component in the record page it worked fine.

0

I ran your code and I was able to create a new contact, as-is.

It's possible that where he was putting his lightning component could be part of the issue, but I just created it as a lightning component, put it in a lightning app, and tested it, which went successfully.

I wonder if there has been a bug fix on Salesforce's end between when this question was asked and now.

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.