function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Pranav S SanvatsarkarPranav S Sanvatsarkar 

What is the default value of OpportunityTeamMember.OpportunityAccessLevel? Was it changed in the recent releases?

Hello there,

I have written an apex class that would create OpportunityTeamMember records ( API ver 32 ). What is the default value of field - OpportunityAccessLevel? 

I think it was Read/Write. Now I think with Salesforce Summer 16 release it is changed to Read-Only. 

One more think I am noticing that older records of OpportunityTeamMember created with reason Sales Team with Access Read/Write were changed to Read-Only.

Any guesses ?? :)

Thanks in advance.
NagendraNagendra (Salesforce Developers) 
Hi Pranav,

Please look at this blog from Jeff Douglas.

I was working on a project the other day where I needed to dynamically add users to an opportunity's Sales Team (OpportunityTeamMember object) so that users who do not normally have access to an opportunity based upon Org-wide security settings can work on the opportunity with other team members. One of the advantages of Sales Teams is that you can specify the level of access that each team member has for the opportunity. Some team members may need read/write access while others may just need read-only access.

From the opportunity page layout, you can add a new team member and specify their access level and role.
User-added image
However, by default when you create a new team member via Apex, the platform grants them read-only access. So I tried to specify grant "Edit" (read/write) access with the following code.
OpportunityTeamMember member = new OpportunityTeamMember();  
member.OpportunityId = SomeOpp.Id;  
member.UserId = SomeUser.Id;  
mmember.TeamMemberRole = 'Sales Rep';  
member.OpportunityAccessLevel = 'Edit';
Specifying the OpportunityAccessLevel threw the following error when saving my class:
​Save error: Field is not writable: OpportunityTeamMember.OpportunityAccessLevel
To be fair, the docs(https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_objects_opportunityteammember.htm) state that OpportunityAccessLevel is not creatable but it used to be with earlier versions of the API so I really wanted this to work and it was screwing up my day.

So here's the solution that I can up with in case anyone is looking for an answer. You need to add the team members to the opportunity and then update the sharing access to the opportunity for these users.
OpportunityTeamMember member = new OpportunityTeamMember();  
member.OpportunityId = SomeOpp.Id;  
member.UserId = SomeUser.Id;  
mmember.TeamMemberRole = 'Sales Rep';

insert member;

// get all of the team members' sharing records
List<OpportunityShare> shares = [select Id, OpportunityAccessLevel,  
  RowCause from OpportunityShare where OpportunityId IN :SomeSetOfOpptyIds 
  and RowCause = 'Team'];

// set all team members access to read/write
for (OpportunityShare share : shares)  
  share.OpportunityAccessLevel = 'Edit';

update shares;
Kindly mark this post as solved if the information help's so that it gets removed from the unanswered queue and becomes a proper solution which results in helping others who are really in need of it.

Best Regards,
Nagendra.P