0

I have this code :

@AuraEnabled(cacheable=false)
    public static Boolean upsertPassengerList(List<requestWrapper> requests){
        List<cms_Passenger_list__c> passengerList = new List<cms_Passenger_list__c>();
        for(requestWrapper r : requests){
            cms_Passenger_list__c p = new cms_Passenger_list__c();
            p.cms_Contact__c = r.contactId;
            p.cms_Travel__c = r.travelId;
            if(r.checked){
                p.cms_Status__c = 'Show';
            }else{
                p.cms_Status__c = 'No Show';
            }
            passengerList.add(p);
        }
        upsert passengerList;
        return true;
    }

JS Code:

   onSaveRecords(){
        upsertPassengerList({'requests' : this.upsertObject}).then((res)=>{
            console.log(res);
        }).catch((err)=>{
            console.log('error on save');
        })
    }

What am I missing? The method is getting called from an LWC and I can safely say that all the parameters are correct.

1 Answer 1

1

Remove cacheable = false from your method and it will solve your issue

@AuraEnabled
    public static Boolean upsertPassengerList(List<requestWrapper> requests){
        List<cms_Passenger_list__c> passengerList = new List<cms_Passenger_list__c>();
        for(requestWrapper r : requests){
            cms_Passenger_list__c p = new cms_Passenger_list__c();
            p.cms_Contact__c = r.contactId;
            p.cms_Travel__c = r.travelId;
            if(r.checked){
                p.cms_Status__c = 'Show';
            }else{
                p.cms_Status__c = 'No Show';
            }
            passengerList.add(p);
        }
        upsert passengerList;
        return true;
    }
8
  • Tried it. Still the same.
    – Snorlax
    Commented Nov 22, 2022 at 6:26
  • Add your js code as well. How you are calling this method Commented Nov 22, 2022 at 6:27
  • Added the JS Code.
    – Snorlax
    Commented Nov 22, 2022 at 6:28
  • This error mostly comes when you try to do dml in @AuraEnabled(cacheable = true) methods. Commented Nov 22, 2022 at 6:35
  • yeah I have read that one up, but I am now stuck and can't find the thing that I am missing. Must be something obvious I don't know.
    – Snorlax
    Commented Nov 22, 2022 at 6:38

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .