Activity Forums Salesforce® Discussions Why we not allowed to use the DML operation inside a constructor in Salesforce apex class?

  • Vikas Kumar

    Member
    January 23, 2017 at 7:38 am

    Hi Mohit,

    Constructor is mainly used to initialization of variables. It is not used for doing DML operations.

    Salesforce has blocked this due to security issues.

    If you want to do DML operation during VF page loading, use action attrirbute in <apex:page>. Call a method from the action in which DML operation is allowed.

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos