Apex Library to dynamically prevent/allow code execution Test Coverage : 100%
This Library aims to dynamically control code execution in apex, validation rule and workflow rule / Process Builder.
Here we go !
This implementation use Platform Cache (Session Cache). Ensure you have platform Cache enabled or the deployment will fail.
If you do not want the version with the Platform Cache, copy the code in the class DCE_NOCACHE.txt to DCE.cls instead
In order to apply the dynamic code execution, wrap you code in a if statement :
trigger myTrigger on myObject (after update) {
if(DCE.allow('myTrigger')) {
MyObjectTriggerDelegate();
}
}If you user as the value "myTrigger" selected in the multipicklist DCE_TriggerBlackList__c the DCE.isAllowed('myTrigger') condition will be false.
You can force to prevent all in your code or in your script either by checking the field DCE_AllTrigger__c or by setting the preventAll boolean to true dynamically :
DCE.preventAll = true;You can force to prevent execution after n execution :
DCE.allowUntil('myTrigger', 2);This way the trigger myTrigger will be executed 2 times.
In order to by pass validation rule you can configure your user with the multipicklist DCE_VBL__c to filter what you want to prevent or you can use the checkbox DCE_AV__c to prevent all. Then configure you're validation rule this way :
Not($User.DCE_AV__c) && NOT(INCLUDES($User.DCE_VBL__c,'MyValidationRule')) && MyConditionsIn order to by pass Workflow rule or Process Buidler you can configure your user with the multipicklist DCE_WBL__c to filter what you want to prevent or you can use the checkbox DCE_AW__c to prevent all. Then configure you're workflow rule / Process Builder this way :
Not($User.DCE_AW__c) && NOT(INCLUDES($User.DCE_WBL__c,'MyFlow')) && MyConditions- Sebastien Colladon - Initial work - scolladon