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 thatyou 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.
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.
Specifying the OpportunityAccessLevel threw the following error when saving my class:
Save error: Field is not writable: OpportunityTeamMember.OpportunityAccessLevel
To be fair, the docs 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 a answers. You need to add the team members to the opportunity and then update the sharing access to the opportunity for these users.