+ Start a Discussion
JNicJNic 

DML Currently not allowed

Hey all,

 

I'm trying to make a component for adding inline notes to any record.

 

But each time I call the {!addNote} action, I get "System.Exception: DML currently not allowed"

 

I don't know why that is, some explanation would be hot.

 

 

Here is my controller:

 

 

public class GenericInlineNoteComponentController { // External variables public List<Note> n {get; set;} public String myObjectId {get; set;} public GenericInlineNoteComponentController() { Id thisId = myObjectId; n = new List<Note>(); Note newNote = new Note(); newNote.ParentId = thisId; //Add the new line right off the bat n.add(newNote); } //Save public PageReference addNote() { insert n; return null; } }

 

Everything displays correctly till addNote is called.

 

 

 

Thanks,

JNH


 

prageethprageeth

Hello JNic;

I dont think that the problem is with your "addNote()" method.The problem is may be with the place where you call the "addNote()" method. In some places it is not allowed to do DML operations. For an example in your constructor you cant do a DML operation(So you can't call the "addNote()" method in constructor). Could you please tell us how/where do you call the "addNote()" method.  

XactiumBenXactiumBen

If you want to use dml statements in a component you have to use the allowDML attribute in the visualforce component tag:

 

<apex:component allowDML="true"> ...

 

HariPHariP
I have Visualforce as a Quick Action on Case and got the same error. I have try catch block in constructor and creating an Error log if there is any error. There is an exception in the code and that caused to create Error Log in constructor. Since VF components won't allow DML either you have to add allowDML="true" or fix the errors before reaching any DML statements. I commented try catch block, tested and fixed errors and then added try catch block.

Is this Visualforce Component? If yes you can add allowDML="true"
Refer this: http://salesforce.stackexchange.com/questions/32138/system-limitexception-dml-currently-not-allowed

Thanks
Hari