Skip to main content
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 6 years ago

Rationale

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.

Scope 

  • Apex classes

Did this answer your question?