You need to sign in to do that
Don't have an account?
Chinu_SFDC
can someone please explain me the trigger to - "Add Opportunity owner to sales team when a new Opportunity is created"
Let say a new Opportunity is created by Rohit... As soon as a new opportunity is created by Rohit, I want to add him to sales team.
Please help me in explaining the code !
Please help me in explaining the code !
First you need to create Opportunity Team Selling so go to below step:
Click Your Name | Setup | Customize | Opportunities | Opportunity Team Selling.
Click the Enable Team Selling or Disable Team Selling link.
Select or deselect the Team Selling Enabled checkbox and click Save. Enabling team selling gives your users access to create and use sales teams on opportunities.
If you are enabling team selling, select the opportunity page layouts that should include the new Sales Team related list and click Save.
Use below code:
// Trigger Code
trigger triggerOnOpportunity on Opportunity (after insert) {
if(trigger.isInsert && trigger.isAfter){
CreateUserAsSalesTeamMember.CreateUserAsSalesTeamMember_method(trigger.new);
}
}
// Class code
public class CreateUserAsSalesTeamMember {
public static void CreateUserAsSalesTeamMember_method(List<Opportunity> opportunityList){
List<OpportunityTeamMember> otmList = new List<OpportunityTeamMember>();
for(Opportunity oppObj : opportunityList){
OpportunityTeamMember otmObj = new OpportunityTeamMember();
otmObj.UserId = oppObj.OwnerId;
otmObj.OpportunityId= oppObj.Id;
otmList.add(otmObj);
}
upsert otmList;
}
}
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks,
Ajay Dubedi