So I understand DML Operations aren't allowed in getters/setters,constructors but it was my understanding that they were allowed in methods that were invoked by page-actions like so:


<apex:page controller="mycontroller" action="{!init}">...</apex:page>


public mycontroller(){
   public void init(){
        //perform some DML, in my case inserting a custom setting if one doesn't exist...
        insert whatever...;

This worked fine for a while, but than when I attempted to deploy my app into a Spring '13 sandbox org I get an exception:

DML currently not allowed An unexpected error has occurred. Your development organization has been notified.

Has this always been the case and I'm doing something different I didn't realize?

If not some suggestions how I could create my necessary custom settings if they don't exist on page-init would be great.

  • I can use DML in a page action in a Winter '13 DE without any problem, so if it isn't working it is new in Spring '13. Is it in a component? Then you need to specify the allowDML="true". Jan 23, 2013 at 23:39
  • It's not in a component, it's in a page that is loaded inside of a visualforce tab though... Jan 23, 2013 at 23:40
  • Works for me in a VF tab as well in a Winter '13 DE. Seems like it should "just work" if you haven't changed API versions of the page, class, or anything like that. Jan 23, 2013 at 23:50
  • This is weird. I just moved the location of the call and it's working for me as well! Ok -- going to leave this for the moment until I figure it out. Jan 23, 2013 at 23:58

1 Answer 1


I once started seeing this error and couldn't work out for the life of me why... I eventually realised I was being a bit dim, and following my oft-used practice had a call to Init() inside a constructor, and you can't perform DML operations like this inside the constructor!

Update Jan 2014 - Something else to watch out for!

Almost a year after writing this answer I hit a similar issue yesterday, this time because the controller was for a Visualforce component as opposed to a page. In a component you must explicitly allow DML like so:

<apex:component controller="myController" allowDML="true">
  • Nice caveat @LaceySnr! How do you get these pages and components through Security Review process with DML in the action? Did you need to justify an exceptional case to them? Jan 7, 2014 at 23:04
  • This is just in an action fired from a button, not on load. I do have one on load though and yes, I just had to explain that the auto-test reported a false positive and that the DML would be in no way damaging to system data.
    – Matt Lacey
    Jan 8, 2014 at 2:28
  • I had this same problem with an action button and this solution worked for me.
    – Shanerk
    Feb 22, 2019 at 15:32

You must log in to answer this question.

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