0

I'm trying to update an object which is created when the init method is called. I'm using <lightning:recordEditForm along with <lightning:inputField to capture the fields and map them to the record.

The form is on a Community Page so I'm confused about how to set recordId

<aura:component implements="forceCommunity:availableForAllPageTypes,force:hasRecordId"

     <aura:attribute name="recordId" type="String" default="a101l0000098dUV" />


     <lightning:recordEditForm recordId="{!v.recordId}" objectApiName="XXX__c">

The problem I'm having is when I remove the recordId value from <lightning:recordEditForm the form loads but when a value is added the form does not load.

I want to take these fields and update a record which has been created to store files which have been uploaded during the progression of the form.

Is this down to not having a record to fetch as it is part of a community page?

Can you not enter another recordId bar the one supplied via force:hasRecordId"?

** I did not design this component so it could be down to some logic I have not found yet it is pretty straightforward though. Everything works a record is created but I want to update a record not create one. At the moment, I create two records one in the init method this is the one to be updated. The other is the record the form is creating when submitted.

1 Answer 1

1

You have to be careful when using both force:hasRecordId and <aura:attribute name="recordId" ..., as this can cause problems. If I had to guess, it might be because of missing access attribute access="global", or the default value isn't applied correctly, because it already has a value from force:hasRecordId, or perhaps even because that property might be marked as read-only. I'd suggest an alternative attribute and set that value instead.

The following markup declares an aura:valueInit handler, a separate attribute to use, and then we change the form to use that new attribute.

<aura:handler name="init" value="{!this}" action="{!c.doInit}" /> 
<aura:attribute name="editRecordId" type="String" />
<lightning:recordEditForm recordId="{!v.editRecordId}" objectApiName="XXX__c">

And now we set up our handler:

doInit: function(c, e, h) {
  let recordId = c.get("v.recordId");
  // sets the record Id or uses the default value
  c.set("v.editRecordId", recordId || "a101l0000098dUV");
}
1
  • Not sure what the problem is I have tried what you suggested and the form freezes at the same point. It seems to freeze when <lightning:recordEditForm recordId="{!v.editRecordId}" objectApiName="XXX__c"> is added to the form this record is created. Where when I use the form to create a record <lightning:recordEditForm aura:id="xxx" objectApiName="xxxx" onsubmit="{!c.handleSubmit}" onerror="{!c.handleError}" onsuccess="{!c.handleSuccess}"> is works.
    – Sean
    Commented Feb 22, 2023 at 10:06

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .