<lightning:button onclick="{!c.saveForm}"


saveForm : function(cmp, event, helper) {

    var upsertRecordAction = cmp.get('c.upsertRecord');
    var record = cmp.get('v.record');

    if (!record.sobjectType) {
        record.sobjectType = cmp.get('v.sObjectName');

        recordToUpsert: record

        function(response) {
            var state = response.getState();

            console.log('FieldSetFormController upsertRecordAction callback');
            console.log("callback state: " + state);

            var toastEvent = $A.get("e.force:showToast");

            if (cmp.isValid() && state === "SUCCESS") {
                    "title": "Success!",
                    "message": "The record has been upserted successfully.",
                    "type": "success"

            else if (state === "ERROR") {
                var errorMessage = response.getError()[0].message;

                    "title": "Error",
                    "message": "The record was not saved. Error: " + errorMessage,
                    "type": "error"


Apex controller

@AuraEnabled public static void upsertRecord(SObject recordToUpsert) { upsert recordToUpsert; }

  • Welcome to SFSE! Please make sure to include the relevant portions of your code (we don't necessarily need to see everything), along with the specific issue you are struggling with and the complete text and location of any errors, in the body of your question. See How to Ask for more about our expectations, and please edit your question to add information rather than posting comments. – David Reed May 2 at 11:57
  • Okay..Modified.Now i need to add save and edit functionality in cmp and controller.js ..I have tried with the record form in component but all the fields from the account object are displaying But i need to display only fields from the fieldset – P Aashi May 2 at 12:17

still you didn't mention where exactly you struck up. i didn't understand why you used lightning:recordForm inside Lightning:recordeditform. i think you just need Lightning:recordeditform in your case if i understood correctly. please try below code. and please add your errors if you get

<aura:component controller="kalpita_123.FieldSetForn" implements="flexipage:availableForRecordHome,force:hasRecordId,force:hasSObjectName,flexipage:availableForAllPageTypes">
<aura:attribute name="fieldSetName" type="String" description="The api name of the field set to use from the given object." />
<aura:attribute name="sObjectName" type="String"/>

<aura:attribute name="fields" type="Object[]" access="global" />
 <lightning:notificationsLibrary aura:id="notifLib" />
<aura:handler name="init" value="{!this}" action="{!c.init}" />
<aura:handler event="force:refreshView" action="{!c.init}" />

<lightning:recordEditForm aura:id="test"
                          objectApiName="{! v.sObjectName }"
                          recordId="{! v.recordId }"
                          recordTypeId="{! v.recordTypeId }"
    <aura:iteration items="{! v.fields }" var="field">
        <lightning:inputField fieldName="{! field.APIName }" class="slds-p-top_small slds-m-top_medium" />
<lightning:button class="slds-align_absolute-center" type="submit" label="Save" variant="brand"/>


 init: function(cmp, event, helper) {

    var fieldSetName = cmp.get('v.fieldSetName');
    var sobjectName = cmp.get('v.sObjectName');
    var recordId = cmp.get('v.recordId');

    if (!fieldSetName) {
        console.log('The field set is required.');

    var getFormAction = cmp.get('c.getForm');

        fieldSetName: fieldSetName,
        objectName: sobjectName,
        recordId: recordId

        function(response) {
            var state = response.getState();
            console.log('FieldSetcmpController getFormAction callback');
            console.log("callback state: " + state);

            if (cmp.isValid() && state === "SUCCESS") {
                var form = response.getReturnValue();
                cmp.set('v.fields', form.Fields);
handlesave : function(cmp,event,helper){
var fields = event.getParam("fields");
 handleSuccess: function (cmp, event, helper) {
        "title": "Record updated!",
        "message": "The record "+ event.getParam("id") + " has been updated successfully.",
        "variant": "success"


still there is lot of options in lightning:recordform like onload,onerror please check here https://developer.salesforce.com/docs/component-library/bundle/lightning:recordEditForm/documentation

  • Thanks..but i dont want lightning:recordEditForm as i want fields from the fieldset.I want custom edit..pls let me know how to do that – P Aashi May 2 at 14:30
  • @PAashi , what you mean custom edit? can you please elaborate your use case – sdandamud1 May 2 at 15:14
  • custom edit is nothing but our own logic for edit and save using fieldset – P Aashi May 3 at 8:08
  • I have updated my save code where the fields from the fieldset should be saved..But its not working, any help @sdandamud1 – P Aashi May 3 at 8:12

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.