Exception:
If you use below code it will throw an error System.LimitException: Too many DML statements: 1 ,it is because you have an dml statement in your aura-method which is enabled for cache.
Workaround:
Please remove (cacheable=true) from your method declared above,then this will work without any error
If you use below code it will throw an error System.LimitException: Too many DML statements: 1 ,it is because you have an dml statement in your aura-method which is enabled for cache.
public with sharing class GetAllAccountsCntrl { @AuraEnabled(cacheable=true) public static List<Account> processAllAccounts() { List<Account> lstAcc = new List<Account>(); for(Account acc:[SELECT Id, Name,AccountSource,Website, Createddate FROM Account Limit 10]) { acc.Name = 'LWC Testing...'; lstAcc.add(acc); } Database.update(lstAcc,false); return lstAcc; } }
Please remove (cacheable=true) from your method declared above,then this will work without any error
public with sharing class GetAllAccountsCntrl { @AuraEnabled public static List<Account> processAllAccounts() { List<Account> lstAcc = new List<Account>(); for(Account acc:[SELECT Id, Name,AccountSource,Website, Createddate FROM Account Limit 10]) { acc.Name = 'LWC Testing...'; lstAcc.add(acc); } Database.update(lstAcc,false); return lstAcc; } }
Please comment or write us if you have any queries/requirements.
Please like,follow,bookmark,subscribe this site to receive daily updates.
Please like,follow,bookmark,subscribe this site to receive daily updates.
refreshApex is not working if cacheable=true removed.
ReplyDeletethanks
ReplyDeleteI have removed cacheable = true and i m not even using wire but still getting too many dml statements : 1
ReplyDeleteHow do i fix this
use @AuraEnabled(cacheable=false) and try. it will work.
DeleteI had tried with (cacheable=false). Still getting the same issue.
Delete