1

I am creating a LWC that has a data table where you can check some boxes, and then a button that should update a particular field on those rows. Nothing crazy. But I am getting this error: System.LimitException - Too Many DML Statements: 1.

editStores()
{
    var selectedRecords = this.template.querySelector("lightning-datatable").getSelectedRows();  
    //console.log(selectedRecords);

    updateStores({stores: selectedRecords})  
    .then(result=>{  
      return refreshApex(this.stores);  
    })  
    .catch(error=>{  
        this.errorMsg = JSON.stringify(error);  
    })  

}

Then the Apex controller:

    @AuraEnabled(cacheable=false)
    public static void updateStores(List<Customer_Notes_Accounts__c> stores) {
        for(Customer_Notes_Accounts__c s : stores)
        {
            s.Implementation_Date__c = Date.today();
        }
        
        update stores;
    }

I have done plenty of googling and every result says 1. I can't have cacheable as true since my method does DML (I removed it and even explicitly set it to false) and 2. I need to call it imperatively (I am). I am stumped on what else to do here. Can anyone help?

5
  • Have you tried updating the records in bulk instead of updating them individually ? Jul 18, 2023 at 17:29
  • 3
    Consider trying to do a hard refresh (and/or manually clear your cache). It's possible your browser is still caching something from before you made the change to cacheable=false.
    – Adrian Larson
    Jul 18, 2023 at 17:34
  • Use debug and check what processes are running. Maybe the object Customer_Notes_Accounts__c has many processes in flows/triggers
    – Liron C
    Jul 18, 2023 at 18:01
  • Your code is still missing bulkification elements, such as adding each store where you need updates s.Implementation_Date__c = Date.today(); to a List and then update the list outside the FOR loop. Also, chacheble=false is correctly annotated. Even after these changes, if you encounter issues, check for any other DML operations being executed before or after this code. Jul 19, 2023 at 4:49
  • Can you add your comment as an answer @AdrianLarson?
    – MikeA
    Oct 10, 2023 at 13:31

1 Answer 1

0

Consider trying to do a hard refresh (and/or manually clear your cache). It's possible your browser is still caching something from before you made the change to cacheable=false.

You must log in to answer this question.

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