Storable Action - System.LimitException: Too many DML statements: 1
@AuraEnabled(cacheable=true)
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)) {
returnList.add(thisContact);
}
try {
delete returnList;
return'deleted successfully';
}
catch(Exception ex){
return 'Problem occoured';
}
}
JS Method
deleteSelected(){
deleteContacts({
contactIds :this.selectedIds
})
.then(result => {
this.dispatchEvent(
new ShowToastEvent({
title: 'Success',
message: result,
variant: 'success',
}),
);
return refreshApex(this.getContactList, { searchKeyWord: '$searchKeyWord' });
})
.catch(error => {
this.error = error;
});
apex lightning limitexception storable-action
add a comment |
@AuraEnabled(cacheable=true)
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)) {
returnList.add(thisContact);
}
try {
delete returnList;
return'deleted successfully';
}
catch(Exception ex){
return 'Problem occoured';
}
}
JS Method
deleteSelected(){
deleteContacts({
contactIds :this.selectedIds
})
.then(result => {
this.dispatchEvent(
new ShowToastEvent({
title: 'Success',
message: result,
variant: 'success',
}),
);
return refreshApex(this.getContactList, { searchKeyWord: '$searchKeyWord' });
})
.catch(error => {
this.error = error;
});
apex lightning limitexception storable-action
add a comment |
@AuraEnabled(cacheable=true)
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)) {
returnList.add(thisContact);
}
try {
delete returnList;
return'deleted successfully';
}
catch(Exception ex){
return 'Problem occoured';
}
}
JS Method
deleteSelected(){
deleteContacts({
contactIds :this.selectedIds
})
.then(result => {
this.dispatchEvent(
new ShowToastEvent({
title: 'Success',
message: result,
variant: 'success',
}),
);
return refreshApex(this.getContactList, { searchKeyWord: '$searchKeyWord' });
})
.catch(error => {
this.error = error;
});
apex lightning limitexception storable-action
@AuraEnabled(cacheable=true)
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)) {
returnList.add(thisContact);
}
try {
delete returnList;
return'deleted successfully';
}
catch(Exception ex){
return 'Problem occoured';
}
}
JS Method
deleteSelected(){
deleteContacts({
contactIds :this.selectedIds
})
.then(result => {
this.dispatchEvent(
new ShowToastEvent({
title: 'Success',
message: result,
variant: 'success',
}),
);
return refreshApex(this.getContactList, { searchKeyWord: '$searchKeyWord' });
})
.catch(error => {
this.error = error;
});
apex lightning limitexception storable-action
apex lightning limitexception storable-action
edited Jan 17 at 16:14
Adrian Larson♦
107k19113241
107k19113241
asked Jan 16 at 18:15
keeplerkeepler
20128
20128
add a comment |
add a comment |
3 Answers
3
active
oldest
votes
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.
add a comment |
Reason for that is your
cacheable=true
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.
https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/controllers_server_apex_auraenabled_annotation.htm
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.
add a comment |
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.
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "459"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsalesforce.stackexchange.com%2fquestions%2f246851%2fstorable-action-system-limitexception-too-many-dml-statements-1%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
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.
add a comment |
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.
add a comment |
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.
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.
edited Jan 16 at 18:27
answered Jan 16 at 18:21
Adrian Larson♦Adrian Larson
107k19113241
107k19113241
add a comment |
add a comment |
Reason for that is your
cacheable=true
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.
https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/controllers_server_apex_auraenabled_annotation.htm
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.
add a comment |
Reason for that is your
cacheable=true
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.
https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/controllers_server_apex_auraenabled_annotation.htm
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.
add a comment |
Reason for that is your
cacheable=true
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.
https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/controllers_server_apex_auraenabled_annotation.htm
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.
Reason for that is your
cacheable=true
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.
https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/controllers_server_apex_auraenabled_annotation.htm
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.
answered Jan 16 at 18:21
Manjot SinghManjot Singh
2,310622
2,310622
add a comment |
add a comment |
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.
add a comment |
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.
add a comment |
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.
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.
answered Jan 16 at 18:21
David ReedDavid Reed
32.9k72052
32.9k72052
add a comment |
add a comment |
Thanks for contributing an answer to Salesforce Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsalesforce.stackexchange.com%2fquestions%2f246851%2fstorable-action-system-limitexception-too-many-dml-statements-1%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown