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
IntegrationUserIntegrationUser 

Problems trying to insert a row into AccountShare via the API

When I try to insert a row into accountshare and include the ContactAccessLevel field, I get the following error message:

fields:ContactAccessLevel', message:'AccountShare: bad field names on insert/update call: ContactAccessLevel, statusCode:'INVALID_FIELD_FOR_INSERT_UPDATE',}

However, if I exclude this field I get the following error message:

fields:AccountAccessLevel, OpportunityAccessLevel, CaseAccessLevel, message:
:AccountAccessLevel,OpportunityAccessLevel,CaseAccesLevel(Account,Opportunity,Case Levels, Con Levels(All, Edit, None, Edit) are below organization levels(Read, None, None, ControlledByParent))', statusCode:'INVALID_ACCESS_LEVEL'),}

Here is the JavaScript code I am using in my S-Control:

var newAccountShare = new sforce.SObject("AccountShare");
newAccountShare.UserOrGroupId = randomUserId;
newAccountShare.AccountId = accountId;
newAccountShare.AccountAccessLevel = "All";
newAccountShare.OpportunityAccessLevel = "Edit";
newAccountShare.CaseAccessLevel = "Edit";
newAccountShare.ContactAccessLevel = "Edit";
var createResults = sforce.connection.create([newAccountShare]);
Ron HessRon Hess
I found this in the docs:

This field must be set to an access level that is at least equal to the organization’s default ContactAccessLevel. This field cannot be updated via the API if the ContactAccessLevel field is set to “Controlled by Parent,” you cannot update this field for the associated account owner using the API. You must update the account owner’s ContactAccessLevel via the Salesforce user interface.


is it possible that you have controlled by parent enabled ?