0

I have a record edit form on which I'm binding my record id. When I pass record ID as hardcoded form then the lightning record edit form gets loaded but when I'm passing that ID dynamically record edit form does not load.Below is the code :

.HTML

<template if:false={viewForm}>
        <lightning-record-edit-form record-id={closeoutId} object-api-name="Contract_Close_Out__c">
          
            <lightning-output-field field-name="Contract_Type__c">
            </lightning-output-field>
            <lightning-input-field field-name="Anticipated_Close_out_date__c">
            </lightning-input-field>
            <lightning-input-field field-name="Evidence_of_physical_completion__c">
            </lightning-input-field>
            <lightning-input-field field-name="Contractual_Warranty__c">
            </lightning-input-field>
            <lightning-button class="slds-m-top_small" variant="brand" type="submit" name="update" label="Update">
            </lightning-button>
        </lightning-record-edit-form>
    </template>


.JS

onEditHandler(){
   
    getCloseOutId({
        id : this.recordId
    }).then(result => {
        this.closeoutId = 'a0z1G00000BOVxvQAH'; //Record edit form gets loaded
        this.closeoutId =  result.map((item) => (item.Id)); //Record edit form does not get loaded,although in console I can see the ID printed.
        console.log('this.closeoutId : '+this.closeoutId);
        this.viewForm = false;
})
}
3
  • could it be a caching issue? have you tried @AuraEnabled(cacheable=false) on your apex method? Commented Feb 15, 2022 at 10:43
  • @Dextersecret No unfortunately it dosen't work. And as I already mentioned that I am able to get my ID printed in console. Commented Feb 15, 2022 at 11:01
  • if your "this.closeoutId" needs to be a String, it may help adding the zero index [0] at the end i.e. result.map((item) => (item.Id))[0] Commented Feb 15, 2022 at 11:52

2 Answers 2

1

Could it be that the array is passed instead of the id parameter to the form?

The reason why you didn't recognize that it's an array

let ids = ['someidsdfsdfsdf'];
console.log('ids => ' + ids); // Output: ids => someidsdfsdfsdf
console.log('ids => ', ids);  // Output: ids =>  ["someidsdfsdfsdf"]

To avoid this you can either use , instead of + in the log as in the second console log.

2
  • Nope it still doesn't work, I guess the issue is that record Id is not getting binded. Because this record edit form is of a child object. Commented Feb 15, 2022 at 13:42
  • Hi @IndreshBhargav, I've updated the answer above, see if that may point in the right direction. Commented Feb 15, 2022 at 14:31
0

Before calling the getCloseOut() method, a spinner should be displayed and when result is returned then closeoutId should be populated only once and then mark viewForm as False.

Following is snippet with change

onEditHandler(){
  this.viewForm = true; //Display a spinner here
getCloseOutId({
    id : this.recordId
}).then(result => {
    this.closeoutId =  result.map((item) => (item.Id)); //Record edit form does not get loaded,although in console I can see the ID printed.
    console.log('this.closeoutId : '+this.closeoutId);
    this.viewForm = false;
})}

Because you are updating the closeoutId twice, the form is not rendering the changed value.

You must log in to answer this question.

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