Submit recordEditForm from another’s success?

Question:
I have two <lightning:recordForm>
components in my Aura component. When the first form submits and succeeds, I want to automatically submit the second form to make it appear as a single transaction to the user.
I am using the onsuccess
handler of the first form to call:
component.find('caEditForm').submit(fields);
However, the fields
in event.getParams("fields")
come from the first form, not the second. I cannot find a way to retrieve the fields for the second form dynamically.
I also tried adding an onchange
handler to the second form to manually construct a fields list, but this does not include field names. Using event.getSource().get("v.fieldName")
resulted in a strict mode error:
Salesforce aura TypeError: 'caller', 'callee', and 'arguments' properties may not be accessed on strict mode functions or the arguments objects for calls to them at Function.invokeGetter
How can I submit the second form correctly with its own fields?
Answer:
The main issue is that the fields parameter in event.getParams("fields")
contains only the values from the first form. The submit(fields)
method requires fields specific to the second form.
Boost your career with CRS Info Solutions’ Salesforce training , offering expert guidance, practical experience, and comprehensive knowledge—enroll for a free demo now!!!
Solution 1: Manually Prepare Fields for the Second Form
Instead of passing fields
from the first form, construct the field values manually before calling submit()
.
handleMoveSaveSuccess: function(component, event, helper) {
let fields = {
Field_API_Name1__c: component.get("v.someValue1"),
Field_API_Name2__c: component.get("v.someValue2")
};
component.find("caEditForm").submit(fields);
}
Ensure that Field_API_Name1__c
and Field_API_Name2__c
are correctly populated from component attributes or another data source.
Solution 2: Store Second Form’s Field Values in an Attribute
Use an onchange
handler on the second form’s fields to track their values in an Aura attribute.
<lightning:input aura:id="field1" name="Field_API_Name1__c" value="{!v.secondFormValues.Field_API_Name1__c}" onchange="{!c.handleFieldChange}" />
Then, use this stored data when submitting the second form:
handleMoveSaveSuccess: function(component, event, helper) {
let fields = component.get("v.secondFormValues");
component.find("caEditForm").submit(fields);
}
Solution 3: Chain Form Submissions Without Fields
If the second form doesn’t need pre-populated values and should simply submit, call:
handleMoveSaveSuccess: function(component, event, helper) {
component.find("caEditForm").submit();
}
This works if the second form already holds the correct values.
Summing Up
To submit a second <lightning:recordForm>
after the success of the first, you must manually construct its field values instead of relying on event.getParams("fields")
, which only contains data from the first form. The best approach is to store the second form’s field values in an Aura attribute or prepare them dynamically before calling submit()
. If the second form already holds the correct values, you can simply trigger submit()
without passing fields, ensuring a seamless user experience.
Unlock Your Career Potential: Salesforce Training in Jaipur
Transform your career with comprehensive Salesforce training in Jaipur . Our expertly crafted program covers Admin, Developer, and AI tracks, combining in-depth modules, real-world projects, and interactive sessions to help you master Salesforce. Designed to prepare you for certifications, interviews, and a thriving career in the tech industry, our training ensures you’re industry-ready.
Join our free demo class to experience a hands-on, practical approach to learning. Guided by seasoned professionals, you’ll effortlessly navigate even the most advanced Salesforce concepts. Whether you’re a beginner or seeking to elevate your expertise, our training equips you with the skills to solve real-world problems and excel in your field.
Don’t wait—enroll in our free demo today and take the first step toward a successful Salesforce career!!!