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
Ankit GuptaAnkit Gupta 

Unable to insert Account Share object through apex code


A user is running a class in without sharing context and still the user is not able to insert AccountShare object record through  apex code. When i searched online , I found that a user should have modify all data permission to insert the AccountShare record.

But when there is another custom object to which the user has absolutely no access , he is able to insert the record through apex code.

Is this a salesforce bug or what?How can i overcome this.

Any ideas are much appreciated.

HI Ankit, Have you checked if the OWD for Account is very restrictive or less restrictive than the access the user is trying to insert in AccountShare. Because one reason why the insert fails is that the sharing access that is being inserted is less than the access level defined in OWD. 

Check the below post for more information on this
Ankit GuptaAnkit Gupta
Hi Ramu,

I have owd set to Private for Account  & other related objects like Opportunity and contact and I am providing Full Read/Write through my code.