+ Start a Discussion

DML currrently not allowed in method called from a constructor

Hi all,


I am trying to perform a DML operation in a method that is called by the page controller constructor.

I know DML is not allowed in the constructor - is it also not allowed in any methods called by the constructor?


Since I am using an apex page, I can't use the 'allowDml' attribute. The other possible solution I found was to use an action on the page.

My page already has an action - can I have multiple actions on the page, or only one?


Are there any other ways to get around this?



Until the constructor returns, you cannot call any dml. If you want to perform dml, use the action attribute on apex:page.

 you  call other method inside the action method


<apex:page controller="Test123" action="{!Test}">



public class Test123 {


public string Test2() {
      return 'ABC';


public PageReference Test() {
return null;


Yoganand GadekarYoganand Gadekar

If your method(which has a dml) is getting called from constructor then it equivalent ot doing a DML in the constructor itself.. and DMl as you know is not allowed in Constructor.