Last active
February 23, 2017 14:46
-
-
Save wes1278/c2ecdd821e1a4d10383423ff3c26a5c2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //util class | |
| public class util_triggerKillswitch { | |
| public static Boolean shouldRun(String sobjectAPIName) { | |
| for (Trigger_to_Skip__c t : Trigger_to_Skip__c.getall().values()) { | |
| if (t.Sobject_API_Name__c.equalsIgnoreCase(sobjectAPIName)) { | |
| return false; | |
| } | |
| } | |
| return true; | |
| } | |
| } | |
| //inside the trigger | |
| if (util_triggerKillswitch.shouldRun('Account') | |
| { | |
| // trigger code | |
| } | |
| //custom setting named Trigger_To_Skip__c.object | |
| <?xml version="1.0" encoding="UTF-8"?> | |
| <CustomObject xmlns="http://soap.sforce.com/2006/04/metadata"> | |
| <customSettingsType>List</customSettingsType> | |
| <enableFeeds>false</enableFeeds> | |
| <fields> | |
| <fullName>SObject_API_Name__c</fullName> | |
| <caseSensitive>false</caseSensitive> | |
| <externalId>false</externalId> | |
| <label>SObject API name</label> | |
| <length>255</length> | |
| <required>true</required> | |
| <trackTrending>false</trackTrending> | |
| <type>Text</type> | |
| <unique>true</unique> | |
| </fields> | |
| <label>Trigger to skip</label> | |
| <visibility>Protected</visibility> | |
| </CustomObject> | |
| //sample batch class usage | |
| private static void disableTrigger(String sobjectName) { | |
| Trigger_to_Skip__c[] existing = [SELECT Id FROM Trigger_to_Skip__c WHERE SObject_API_Name__c = :sobjectName]; | |
| if (!existing.isEmpty()) { | |
| return; | |
| } | |
| Trigger_to_Skip__c skip = new Trigger_to_Skip__c(); | |
| skip.SObject_API_Name__c = sobjectName; | |
| skip.Name = sobjectName.removeEnd('__c'); | |
| INSERT skip; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment