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
Ravi Sankar 12Ravi Sankar 12 

Lightning QuickAction to update child records

I am trying to mass update child records with a lightning quck action on the parent record detail page. Not sure what is wrong with this code. I appreciate your help.
Component 

<aura:component controller="MassUpdateController " implements="flexipage:availableForRecordHome,force:hasRecordId,force:lightningQuickAction" access="global" >
	<aura:attribute name="data" type="object__c[]"/>
    <aura:attribute name="columns" type="List"/>
    <aura:attribute name="recordId" type="String"/>
    <!-- handlers-->
    <aura:handler name="init" value="{!this}" action="{!c.init }"/>        
    <div style="height: 300px">
        <lightning:datatable
            columns="{! v.columns }"
            data="{! v.data }"
            keyField="id"                 
        />
    </div>
</aura:component>


Controller:

({
	
		init: function(cmp,event, helper) {
        cmp.set('v.columns', [
            {label: 'Name', fieldName: 'Name', type: 'text'  }            
          //  {label: 'Provider Email', fieldName: 'ProviderEmail', type: 'email', editable: true },
          //  {label: 'Not Associated to this Location', fieldName: 'NotAssociatedToThisLocation', type: 'checkbox' }
            
        ]);
        helper.fetchData(cmp,event, helper);        
	}
})


Helper

({
    fetchData: function (cmp,event,helper) {
        var RecordId = component.get("v.recordId");
        action.setParams({
        	"recordId" : RecordId
    	});
        var action = cmp.get("c.getRecords");
        
        action.setCallback(this, function(response) {
            var state = response.getState();
            if (state === "SUCCESS") {
                var data = response.getReturnValue();
                cmp.set('v.data',data);
            }
            // error handling when state is "INCOMPLETE" or "ERROR"
        });
        $A.enqueueAction(action);
    }
})

Apex Controller

public class MassUpdateController {
	@AuraEnabled
    public static list<Managed_Care_Provider__c> getRecords(Id recordId){
        system.debug(' record Id ' + recordId);
        list<object__c> lstMC = [SELECT Id,Name from Object__c where Opportunity__c=: recordId];
        system.debug('---- list of MC ' + lstMC);
        return lstMC;
    }
}
Best Answer chosen by Ravi Sankar 12
Ravi Sankar 12Ravi Sankar 12
Solved, In helper I used component instead of cmp

All Answers

Raj VakatiRaj Vakati
I am not seeting any logic here to update .. can you please give me what is thre requirement 

You can do some think like below ..

Refer this link 

http://sfdcmonkey.com/2017/04/30/add-multiple-child-records-lightning-component/
https://rajvakati.com/2018/10/17/lightning-component-clone-with-related-records/
 
Ravi Sankar 12Ravi Sankar 12
Hello Raj,

Thank you for your reply. I have not written the update method. But, this code should atleast display the records.
Ravi Sankar 12Ravi Sankar 12
Solved, In helper I used component instead of cmp
This was selected as the best answer