public static String  deleteContacts(List<String> contactIds) {
    List<Contact> returnList = new List<Contact> ();
    String query = ' SELECT Id,Name, LastName,Department,MobilePhone, Email FROM Contact WHERE id IN : contactIds ';
    for (Contact thisContact:  Database.Query(query)) {
    try {
      delete returnList;
      return'deleted successfully';
    catch(Exception ex){
       return 'Problem occoured';


JS Method
        contactIds :this.selectedIds
    .then(result => {
            new ShowToastEvent({
                title: 'Success',
                message: result,
                variant: 'success',
        return refreshApex(this.getContactList, { searchKeyWord: '$searchKeyWord' });
    .catch(error => {
        this.error = error;

3 Answers 3


Simply remove the (cacheable=true) parameter from your @AuraEnabled annotation. Caching a delete operation does not make any sense, and is not allowed.

If you read Lightning Components Best Practices: Caching Data with Storable Actions, you will note this section:

The general guideline is to cache (mark as storable) any action that is idempotent and non-mutating.

An idempotent action is an action that produces the same result when called multiple times. For example:

  • getPage(1) is idempotent and should be cached
  • getNextPage() is not idempotent and should not be cached

A non-mutating action is an action that doesn’t modify data. Never cache an action that can create, update, or delete data. For example:

  • updateAccount(sObject) is mutating and not idempotent and should not be cached

Your method violates the non-mutating constraint. It looks like this constraint is a must, rather than a should.

  • The problem with this solution is that the Apex method is not called anymore. The cacheable clause is necessary to make the Apex method callable by JS. I guess a different strategy must be followed for calling Apex methods that do DML. Feb 18, 2020 at 15:49
  • @SanderdeJong Sounds like you may have a separate question. I have had no problem calling non-cacheable methods from Aura. Are you using LWC?
    – Adrian Larson
    Feb 18, 2020 at 15:51
  • Yes I am, I am trying to work 100% in LWC (but will not succeed) Feb 18, 2020 at 15:58
  • 1
    It sounds then like your question may simply be how to call non-cacheable Apex from LWC.
    – Adrian Larson
    Feb 18, 2020 at 16:14

Reason for that is your


annotation. When you are doing caching you cannot mutate any data. You can only get data. So thats why no DML operation is allowed i.e Total DML operation allowed are 0.

As given in this doc.


To improve runtime performance, set @AuraEnabled(cacheable=true) to cache the method results on the client. To set cacheable=true, a method must only get data, it can’t mutate data.


You're performing DML in a context that is not supposed to mutate data - a cacheable @AuraEnabled method:

To improve runtime performance, set @AuraEnabled(cacheable=true) to cache the method results on the client. To set cacheable=true, a method must only get data, it can’t mutate data.

This code doesn't actually make sense, though. Why do you have a method called deleteContacts() that doesn't delete anything? The update DML it performs does nothing save to ping the audit fields, so it's not clear whether the correct approach is to remove the annotation, refactor the DML, or something else.

  • 1
    It's a terrible error message from Salesforce, completely unhelpful.
    – Robs
    Feb 3, 2020 at 12:35

You must log in to answer this question.

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