Skip to content

Instantly share code, notes, and snippets.

@samdavyson
Last active August 29, 2015 14:12
Show Gist options
  • Save samdavyson/ef3972bf973d9a211698 to your computer and use it in GitHub Desktop.
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/
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;
}
}
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.');
}
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;
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