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
j_r_roj_r_ro 

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?

 

Thanks.

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

 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() {
Test2();
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.