Programmatically Turn off Triggers/Validations/Workflow

I wanted to explore using a SandboxPostCopy class upon sandbox creation but ideally need to disable triggers, validation and workflow rules first. Is there a way to do this programmatically via apex?

I feel like it should be possible, especially as the Salesforce Toolkit can but is it possible to with apex itself?

Answer

Expanding on my prior comment.

You can use a Custom Setting that can be flagged to disable all the triggers, validation rules, workflows, etc…

Just set it as the first part of the SandboxPostCopy class. The triggers etc.. would still be active, but wouldn’t actually do anything.


Summer `17 is introducing native Metadata access in Apex. It is currently limited to Custom Metadata Types and Layouts. Changing a triggers active state could be another good use case.

Attribution
Source : Link , Question Author : Girbot , Answer Author : Daniel Ballinger

Leave a Comment