Data manipulation in constructors

Prevent all constructors from writing in to the database, so that creation of objects does not have any data-altering side-effects.

Lorenzo Frattini avatar
Written by Lorenzo Frattini
Updated over a week ago


The act of creation  of an object should not alter significant data on the server side or have  other significant side-effects. For this reason using DML statements inside constructors is generally considered unsafe.


  • Apex classes

Did this answer your question?