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 

How do I create a new AccountShare / OpportunityShare row via the API?

I have written an S-Control which switches Account owners to different owners. I would also like to be able to switch any manual shares for accounts and opportunities. I don't seem to be able to create new rows in either the AccountShare or OpportunityShare show because the RowCause field is readonly.

Is there a better way to switch manual AccountShares / OpportunityShares to a different user via the API?


sfdcfoxsfdcfox
You don't specify RowCause, because it is read only (it's determined by the system). Just provide the AccountId (or OpportunityId), CaseAccessLevel, OpportunityAccessLevel, AccountAccessLevel, ContactAccessLevel, and UserOrGroupId. All of the AccessLevel fields are defaulted to the appropriate level if you exclude them (the organization's current sharing levels).
IntegrationUserIntegrationUser
Thanks for your reply. However, I am still having problems. 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]);

Vijay RautVijay Raut

Hi,

 

Have you got any workaround / root cause for this problem? I am also getting same error and looking for workaround.

 

Thanks in advance.

V.R.

Volker_factory42Volker_factory42

It's working with value "manual"

 

 

CaseShare testcaseshare = new CaseShare(UserOrGroupId = curuserID,CaseId = testcase.id,CaseAccessLevel = 'manual');

 

 

 

 

Volker_factory42Volker_factory42

Sorry, it isn't working at all. All my test where coverd, but when I tried it again, I got an error again :-(

Why isn't it working? 

 

I also tried with value 'Read'