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
Sophia GSophia G 

Populate field values using APEX on Aura Lightning Component

I am new to coding and just need some help changing my code below. I have created an aura lightning component on my 'Lead PAX' opportunity record type which shows the related 'Child PAX' opportunity records (lstRecordId) in a checkbox list. I need the fields Check_In_Date__c, Check_Out_Date__c, Total_Amount__c, Deposit_Amount__c to populate with the field values from hasRecordId (oppRecordId) which is the record with my lightning component on it. How do I change the code below so that instead of populating the values I have written into my code, it populates the values from oppRecordId?
@AuraEnabled
    public static void updateRecord(List <String> lstRecordId, String oppRecordId) {
        
        List<Opportunity> lstUpdate = new List<Opportunity>();
        
        for(Opportunity Opp : [SELECT Id, Name, Check_In_Date__c, Check_Out_Date__c, Total_Amount__c, Deposit_Amount__c, SyncedQuoteId 
                               FROM Opportunity 
                               WHERE Id IN : lstRecordId]){
                                   Opp.Check_In_Date__c = date.parse('03/02/2021');
                                   Opp.Check_Out_Date__c = date.parse('03/02/2021');
                                   Opp.Total_Amount__c = decimal.valueof('2281.90');
                                   Opp.Deposit_Amount__c = decimal.valueof('200.00');
                                   
        lstUpdate.add(Opp);
        }
        
        if(lstUpdate.size() > 0){
            update lstUpdate;
            
        }

 
AnudeepAnudeep (Salesforce Developers) 
Hi Sophia, 

If you want to Pass Data to an Apex Controller and have your code work on that data, you should use action.setParams() in JavaScript to set data to pass to an Apex controller.

For sample code, refer to the documentation

Let me know if this helps