+ Start a Discussion
Ankit Singh 6Ankit Singh 6 

Adding Opportunity team to a opportunity

Hi

I have a trigger and a class which creates Follow Up opportunity based on stage, that is if stage is changed to 7. Closed/Won then it creates new follow up opportunity with all values same as parent opportunity except opportunity team.

We want opportunity team gets copied to new opportunity created.
Please guide me through.
Best Answer chosen by Ankit Singh 6
ManojjenaManojjena
Hi Ankit ,
 Yes Ashis is right I saw the field property is notwritable but I have tested below code it is giving teh readwrite access to the record .I am not able to access this blog as it is blocked for me .

Check below code an dtry to implement and bulkify your code if you need any helo please let us know .
OpportunityTeamMember oppRec=[SELECT Id,OpportunityId,TeamMemberRole,UserId FROM OpportunityTeamMember WHERE OpportunityId = 'ClosedOwnOppId' LIMIT 1];
OpportunityTeamMember opptmMem=new OpportunityTeamMember();
opptmMem.OpportunityId=NewlyCreaedOppId;
opptmMem.TeamMemberRole=oppRec.TeamMemberRole;
opptmMem.UserId=oppRec.UserId;
try{
insert opptmMem;
}catch(DmlException de){
  System.debug(de);
}

 

All Answers

ManojjenaManojjena
Hi Ankit ,

What I understood from your post that your code is working for new opportunity creation when you cange the opportunity stage to closed own .
Only thing is that you wnat to add OpportunityTeam Member  for Opportunity .
If yes Please follow below steps .
1 .Assume you have created opportunity for Opportunity closed own .Now you have both opportunity  Id in your scope .
With help of closed own Id you can get thp OpportunityTeam Member Record related to that .
below is the query help you .
SELECT Id,OpportunityAccessLevel,OpportunityId,TeamMemberRole,UserId FROM OpportunityTeamMember

Now you can create an  OpportunityTeam Member by assigning all field value from above record onlything is that Opportunityid you need to assign with newly craeted Opportunity id .
 
Ashish_Sharma_DEVSFDCAshish_Sharma_DEVSFDC
Hi Ankit,

Please have a look into below blog link.
http://blog.jeffdouglas.com/2011/03/17/opportunityaccesslevel-not-writable/

Let us know if it helps you.
ManojjenaManojjena
Hi Ankit ,
 Yes Ashis is right I saw the field property is notwritable but I have tested below code it is giving teh readwrite access to the record .I am not able to access this blog as it is blocked for me .

Check below code an dtry to implement and bulkify your code if you need any helo please let us know .
OpportunityTeamMember oppRec=[SELECT Id,OpportunityId,TeamMemberRole,UserId FROM OpportunityTeamMember WHERE OpportunityId = 'ClosedOwnOppId' LIMIT 1];
OpportunityTeamMember opptmMem=new OpportunityTeamMember();
opptmMem.OpportunityId=NewlyCreaedOppId;
opptmMem.TeamMemberRole=oppRec.TeamMemberRole;
opptmMem.UserId=oppRec.UserId;
try{
insert opptmMem;
}catch(DmlException de){
  System.debug(de);
}

 
This was selected as the best answer
Ankit Singh 6Ankit Singh 6
Thanks Manoj. I tried your code and it worked fine for me.