Last active
August 29, 2015 14:12
-
-
Save samdavyson/ef3972bf973d9a211698 to your computer and use it in GitHub Desktop.
200 Records: Understanding The Limit - http://boldsparks.com/200-records-understanding-the-limit/
This file contains 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
trigger AccountTrigger on Account (after update) { | |
// make a set of all account ids that are not active but previously were active | |
Set<Id> accountsSetToInactive = new Set<Id>(); | |
for(Account acc : trigger.new) { | |
if(!acc.Active_Checkbox__c && trigger.oldMap.get(acc.Id).Active_Checkbox__c) { | |
accountsSetToInactive.add(acc.Id); | |
} | |
} | |
// get all the related contacts and set them to inactive | |
if(!accountsSetToInactive.isEmpty()) { | |
list<Contact> contactsToSetInactive = [SELECT Id,Active_Checkbox__c FROM Contact WHERE AccountId in :accountsSetToInactive]; | |
for(Contact con : contactsToSetInactive) { | |
con.Active_Checkbox__c = false; | |
} | |
update contactsToSetInactive; | |
} | |
} |
This file contains 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
trigger ContactTrigger on Contact (before update) { | |
runCounter.contactTrigger++; | |
for(Contact con : trigger.new) { | |
con.Batch_Size__c = String.valueOf(trigger.new.size()); | |
} | |
system.debug('@@@ Contact Trigger Ran: ' + runCounter.contactTrigger + ' times.'); | |
} |
This file contains 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
list<Account> accounts = [SELECT Id,Active_Checkbox__c FROM Account WHERE Name LIKE 'Account ']; | |
for(Account acc : accounts) { | |
acc.Active_Checkbox__c = False; | |
} | |
update accounts; |
This file contains 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
public class runCounter { | |
public static integer contactTrigger { | |
get { | |
if(contactTrigger == null) { | |
contactTrigger = 0; | |
} | |
return contactTrigger; | |
} set; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment