When creating Opportunity Team Members via the API in an org where Org Wide Defaults (the organization-level sharing settings) are set to Private for Opportunities, a compile error occurs:
COMPILE ERROR: Field is not writeable: OpportunityTeamMember.OpportunityAccessLevel
This error happens because the OpportunityTeamMember.OpportunityAccessLevel field is not editable through the API when Org Wide Defaults are configured as Private for Opportunities. In this configuration, Salesforce does not allow the access level to be set programmatically via the API.
This error can be avoided by removing references to OpportunityAccessLevel from any Apex code that inserts new OpportunityTeamMember records.
OpportunityTeamMember records can still be created via API even when Org Wide Defaults are set to Private for Opportunities. The solution is to omit the OpportunityAccessLevel field from the Apex insert statement entirely.
For example this code successfully creates a new Opportunity Team Member via API:
insert new opportunityteammember(OpportunityId='006000000000000AAD', TeamMemberRole='Account Manager', UserId='00500000000000OAA2');
This code returns the error because OpportunityAccessLevel is included in the apex insert statement.
insert new opportunityteammember(OpportunityAccessLevel='Edit', OpportunityId='006000000000000AAD', TeamMemberRole='Account Manager', UserId='00500000000000OAA2');
000384988

We use three kinds of cookies on our websites: required, functional, and advertising. You can choose whether functional and advertising cookies apply. Click on the different cookie categories to find out more about each category and to change the default settings.
Privacy Statement
Required cookies are necessary for basic website functionality. Some examples include: session cookies needed to transmit the website, authentication cookies, and security cookies.
Functional cookies enhance functions, performance, and services on the website. Some examples include: cookies used to analyze site traffic, cookies used for market research, and cookies used to display advertising that is not directed to a particular individual.
Advertising cookies track activity across websites in order to understand a viewer’s interests, and direct them specific marketing. Some examples include: cookies used for remarketing, or interest-based advertising.