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
| trigger LeadTrigger on Lead (before insert, after insert, before update, after update, | |
| before delete, after delete, after undelete) { | |
| new LeadTriggerHandler().run(); | |
| } |
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
| public class LeadTriggerHandler extends TriggerHandler { | |
| List<Lead> newLeads; | |
| public LeadTriggerHandler(){ | |
| newLeads = (List<Lead>) Trigger.new; | |
| } | |
| public override void beforeInsert() { | |
| Set<String> companyNames = new Set<String>(); // Will hold the set of Lead Company Names |
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
| public virtual class TriggerHandler { | |
| // Current context of the trigger, overridable in tests | |
| @TestVisible | |
| private TriggerContext context; | |
| // Constructor | |
| public TriggerHandler() { | |
| this.setTriggerContext(); | |
| } |
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
| trigger LeadTrigger on Lead (before insert, after insert, before update, after update, | |
| before delete, after delete, after undelete) { | |
| if(Trigger.isBefore && Trigger.isInsert) { | |
| LeadTriggerHandler.handleBeforeInsert(Trigger.new); | |
| } | |
| if(Trigger.isAfter && Trigger.isInsert) { | |
| LeadTriggerHandler.handleAfterInsert(Trigger.new); | |
| } |
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
| public class LeadTriggerHandler { | |
| public static void handleBeforeInsert(List<Lead> newLeads) { | |
| Set<String> companyNames = new Set<String>(); // Will hold the set of Lead Company Names | |
| Map<String, ID> accountNamesToId = new Map<String, ID>(); // Will hold the set of Account Names mapped to the Account ID | |
| List<Case> newCases = new List<Case>(); // Will hold the new cases to create | |
| for(Lead l : newLeads){ // Look at each Lead individually | |
| companyNames.add(l.Company); // Add the Lead Company to our set | |
| } | |
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
| // Trigger to search Accounts and create a new Case if a Lead Company Name is being created that matches an existing Account name | |
| trigger LeadTrigger on Lead (before insert) { | |
| Set<String> companyNames = new Set<String>(); // Will hold the set of Lead Company Names | |
| Map<String, ID> accountNamesToId = new Map<String, ID>(); // Will hold the set of Account Names mapped to the Account ID | |
| List<Case> newCases = new List<Case>(); // Will hold the new cases to create | |
| for(Lead l : Trigger.new){ // Look at each Lead individually | |
| companyNames.add(l.Company); // Add the Lead Company to our set | |
| } | |