Activity Forums Salesforce® Discussions Why we can't perform DML operations in Constructor?

  • Abhinav

    Member
    August 11, 2016 at 4:09 pm

    Hi Tanu,

    Using insert/update/delete in constructor is a bad practice in any language.

    Establishing connection to DB - OK.
    Constructor is used to create an object and initialize it's parameters; nothing more.
    1. Using DML in constructor will slow down initialization of your object.

    2. It may fail and object just doesn't create at all.

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos