Skip to content

Instantly share code, notes, and snippets.

@dancinllama
Created March 11, 2014 19:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dancinllama/9493289 to your computer and use it in GitHub Desktop.
Save dancinllama/9493289 to your computer and use it in GitHub Desktop.
public class OpportunityTriggerHandler extends TriggerHandler {
private Map<Id, Opportunity> newOpportunityMap = new Map<Id, Opportunity>();
private Map<Id, Opportunity> oldOpportunityMap = new Map<Id, Opportunity>();
private List<Opportunity> triggerNew = new List<Opportunity>();
private List<Opportunity> triggerOld = new List<Opportunity>();
public OpportunityTriggerHandler() {
this.triggerNew = (List<Opportunity>) Trigger.new;
this.triggerOld = (List<Opportunity>) Trigger.old;
}
Public Override void afterUpdate() {
UpdateOppTeam();
}
Private void UpdateOppTeam(){
//Iterate through opportunities, checking whether since this trigger has run, if the opportunity was closed. e.g. if(!Trigger.oldMap.get(newOppty.Id).IsClosed && newOppty.IsClosed)
//For any closed oppties, add the Opportunity Ids to a Set<Id>
//Re-Query opportunities to look for "Manager" role in Owner's role. e.g. [Select Id from Oppty Where OwnerId in :myClosedOpptiesIds and Owner.Role='Manager'];
//Loop through that query, and construct your list of OpportunityTeamMember records.
//Outside of that loop (at the end of your trigger method, insert the list of opportunity team members.
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment