You need to sign in to do that
Don't have an account?

Apex trigger not working with "Add default Team " button on Opportunity
Hey,
SO, I have an Apex trigger on opportunity Team Member which copies the team member with user role = ' Campaign Manager' to "Active_Campaign_Manager__c" field at opportunity. This trigger works fine when I individually add team members but it does NOT work when I click "ADD DEFAULT TEAM". It just does not fire . Below is my code. Please take a look and guide me.
trigger InsertOppTeam2ACM on OpportunityTeamMember (after insert, after update) {
//Using set to be able to work with setOpp and setOTM SETS
set<Id> setOpp = new set<Id>();
set<Id> setOTM = new set<Id>();
for (OpportunityTeamMember oppTeam : trigger.new) {
setOpp.add(oppTeam.OpportunityId);
setOTM.add(oppTeam.id);
}
//Loop through opportunity team members and grab Users who have these roles 'Campaign Manager'.
list<OpportunityTeamMember> listOTM = new list<OpportunityTeamMember>
([
SELECT Id, UserId, OpportunityId, TeamMemberRole, User.Name FROM OpportunityTeamMember WHERE Id IN :setOTM AND
(TeamMemberRole ='Campaign Manager') ]);
// Create a map that grabs the Opportunity Id being worked with
Map<Id,Opportunity> mapOpps = new map<Id, Opportunity>([SELECT Id FROM Opportunity Where Id = :setOpp ]) ;
Opportunity tempOpp;
//Load the ID's
for(OpportunityTeamMember otm : listOTM ){
tempOpp = mapOpps.get(otm.OpportunityId);
if(otm.TeamMemberRole == 'Campaign Manager') {
tempOpp.Active_Campaign_Manager__c = otm.User.Name;
}
}
// Load values
update mapOpps.values();
}
SO, I have an Apex trigger on opportunity Team Member which copies the team member with user role = ' Campaign Manager' to "Active_Campaign_Manager__c" field at opportunity. This trigger works fine when I individually add team members but it does NOT work when I click "ADD DEFAULT TEAM". It just does not fire . Below is my code. Please take a look and guide me.
trigger InsertOppTeam2ACM on OpportunityTeamMember (after insert, after update) {
//Using set to be able to work with setOpp and setOTM SETS
set<Id> setOpp = new set<Id>();
set<Id> setOTM = new set<Id>();
for (OpportunityTeamMember oppTeam : trigger.new) {
setOpp.add(oppTeam.OpportunityId);
setOTM.add(oppTeam.id);
}
//Loop through opportunity team members and grab Users who have these roles 'Campaign Manager'.
list<OpportunityTeamMember> listOTM = new list<OpportunityTeamMember>
([
SELECT Id, UserId, OpportunityId, TeamMemberRole, User.Name FROM OpportunityTeamMember WHERE Id IN :setOTM AND
(TeamMemberRole ='Campaign Manager') ]);
// Create a map that grabs the Opportunity Id being worked with
Map<Id,Opportunity> mapOpps = new map<Id, Opportunity>([SELECT Id FROM Opportunity Where Id = :setOpp ]) ;
Opportunity tempOpp;
//Load the ID's
for(OpportunityTeamMember otm : listOTM ){
tempOpp = mapOpps.get(otm.OpportunityId);
if(otm.TeamMemberRole == 'Campaign Manager') {
tempOpp.Active_Campaign_Manager__c = otm.User.Name;
}
}
// Load values
update mapOpps.values();
}
http://help.salesforce.com/HTViewSolution?id=000187820&language=en_US
I have refined a bit of your code. By the way your code should work, could you share the details about ADD DEFAULT TEAM functionality ,what does it do, does it add array of OpportunityTeamMember ?
Try to insert some list of opportunityTeamMember in anonymous and check if the trigger is getting called or not.
Thanks and Regards,
Shiva RV