function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
valMotovalMoto 

DML currently not allowed when update a Case


Not quite sure what I am missing, but I am getting an error :DML currently not allowed when I try to update the Case.

 

 

Anyone have any ideas? I get the DML error when i call update dupCases

 

here's a snippet of my code.

 

 

List<Case> dupCases = new List<Case>();

for(Case c : cases){
  if(c.Id != Master.Id){
    c.ParentId = Master.Id;
    dupCases.add(c);
  }
}

update dupCases;

 

 

Best Answer chosen by Admin (Salesforce Developers) 
valMotovalMoto

I had "cases" defined at the class level.

 

I figured out the solution. Seems that you cannot execute DML statements when it is called from the constructor of a controller (which i was doing since I wanted an automatic update when the page ran). Instead  I created an action that executes a method on page load.

 

Here is the post where i got the idea:

http://boards.developerforce.com/t5/Visualforce-Development/System-Exception-DML-currently-not-allowed-External-entry-point/m-p/82925/message-uid/82925

All Answers

Regular ContributorRegular Contributor

Can you tell where you have cases.....The code is not clear

valMotovalMoto

I had "cases" defined at the class level.

 

I figured out the solution. Seems that you cannot execute DML statements when it is called from the constructor of a controller (which i was doing since I wanted an automatic update when the page ran). Instead  I created an action that executes a method on page load.

 

Here is the post where i got the idea:

http://boards.developerforce.com/t5/Visualforce-Development/System-Exception-DML-currently-not-allowed-External-entry-point/m-p/82925/message-uid/82925

This was selected as the best answer