Why is DML not allowed in Constructor in Salesforce?

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.

Cheers!!!

No comments:

Post a Comment