function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Abu Zafar WahidAbu Zafar Wahid 

Salesforce lightning component helper method can't assign return value from Apex controller class

Hi everyone,

I'm trying to render multiple dynamic forms, which have different record types. In my lightning component helper class, I have a method where I defined different parameteres and set in the component list type attribute.

My first problem is, I need the dynamic record type Id for the lightning:recordEditForm where I need to set the record type Id. I called the helper method which can pull the record type Id from the server side Apex controller. In this helper method class, I tried to return the record type Id and tried to set the value as below:
var introLaws = [];
                    "key"                    : "DummyKey",
                    "recordType"        : this.getRecordTypeId("Dummy Record Type Name")
component.set("v.lawsSections", introLaws);
I checked the console log, the record type id is good, but whenver I tried use the record type id in component loop, I found that the recordType is empty. The key value is okay. Please advise.

The second problem is, in the component I have a aura:iteration loop to render the dynamic form, and it should be as below:
<aura:iteration items="{!v.lawsSections}" var="lawsSection">
<lightning:recordEditForm aura:id="{!lawsSection.key}" recordTypeId="{!lawsSection.recordType}" objectApiName="Dummy_Object__c">
And here is the issue. I can't assign the recordTypeId, please advise.

My third problem is, I need to assign the dynamic aura:id to save the form, so that I can just use the below structure
var localId = event.getSource().getLocalId();
var notificationApp = component.find(localId);
Please advise.

I appreciate your time.

Kind Regards,
Abu Wahid
Hi Abu, 

You cannot assign the dynamic aura:id to your lightning component. You can do it by givivng dynamic class to your element or using data-id and get it with or you can give simply id to your element and get it with document.getElementbyId.

I think this will solve all your problem . And you will get the recordType too.

You can check the below link its still an idea.

Hope, The above helps you.......!!!!!!!
If the above Solution helps you Please mark it as Best answer So that it will be removed from the queue.