Skip to content

Instantly share code, notes, and snippets.

@LawrenceLoz
LawrenceLoz / AccountHandlerSetActivityDateOnSelf.cls
Last active October 28, 2021 05:40
Trigger and handler class examples - Apex Trigger Actions
public with sharing class AccountHandlerSetActivityDateOnSelf implements TriggerAction.BeforeInsert, TriggerAction.BeforeUpdate {
public void beforeInsert(List<Account> newList) {
setLastAccountTreeActivity(newList);
}
public void beforeUpdate(List<Account> newList, List<Account> oldList) {
setLastAccountTreeActivity(newList);
}
@LawrenceLoz
LawrenceLoz / AccountHandlerSetActivityDateOnSelf.cls
Created March 7, 2021 06:10
Trigger and handler class examples - Nebula Core
public with sharing class AccountHandlerSetActivityDateOnSelf implements BeforeInsert, BeforeUpdate {
public void handleBeforeInsert(List<Account> newList) {
setLastAccountTreeActivity(newList);
}
public void handleBeforeUpdate(List<Account> oldList, List<Account> newList) {
setLastAccountTreeActivity(newList);
}
@LawrenceLoz
LawrenceLoz / AccountHandlerUpdateRelatedContacts
Created February 28, 2021 11:41
Trigger actions illustrating recursion issue
public with sharing class AccountHandlerUpdateRelatedContacts implements TriggerAction.AfterUpdate {
// Updates contacts related to the account to set Last_Account_Update__c to the current date and time
public void afterUpdate(List<Account> newList, List<Account> oldList) {
Map<Id,Account> newMap = new Map<Id,Account>(newList);
List<Contact> contacts = [SELECT Id FROM Contact WHERE AccountId IN :newMap.keySet()];
Datetime timeNow = Datetime.now();
for(Contact con : contacts) {