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
nikita dhamalnikita dhamal 

Help in Apex Sharing

i want to use apex sharing on my 'projects' object which is a custom object  i went through the document:
They have Asked to create MyCustomObject__Share
do ineed to create new Object as projects__Share or edit the existing object...can anyone tell me the steps for the __Share object creation 
piyush parmarpiyush parmar
Hi Nikita,

Shared object is the system object.

You have to change the OWD setting follow the below set to make the private/read onlyobject. 

Setup -> Security Controll -> Sharing Setting -> Edit (make you object Private/Readyonly).

Once the object is the private/readonly the "__Share" object will be craeted. 

You can see the "Share" button in your Project object records.

Naresh YadavNaresh Yadav
Hi nikita

follow the below link.

Hope it will help you out.
nikita dhamalnikita dhamal
Hi piyush , 
 I made changes as you specified.. is the  "__Share" object accesible because m not able to see it in objects . also i have to write sharing class nad m getting error  "Error: Compile Error: Entity is not org-accessible at line 1 column 8" while saving the class
piyush parmarpiyush parmar
Hi Nikita,
It seems to be typo !!!

Maybe you have something like:
MyCustomObject__Share shareObj = new MyCustomObject(); 
insted of
MyCustomObject__Share shareObj = new MyCustomObject__Share(); 
Piyush :)
nikita dhamalnikita dhamal
Hey Piyush,
      m still getting same error:
My code :
public class projectSharing
   public static boolean manualShareRead(Id recordId, Id userOrGroupId){
      Project__Share projshr  = new Project__c();
      // Set the ID of record being shared.
      projshr.ParentId = recordId;
      // Set the ID of user or group being granted access.
      projshr.UserOrGroupId = userOrGroupId;
      // Set the access level.
      projshr.AccessLevel = 'Edit';
      // Set rowCause to 'manual' for manual sharing.
      // This line can be omitted as 'manual' is the default value for sharing objects.
      projshr.RowCause = Schema.Project__Share.RowCause.Manual;
      // Insert the sharing record and capture the save result. 
      // The false parameter allows for partial processing if multiple records passed 
      // into the operation.
      Database.SaveResult sr = Database.insert(projshr,false);

      // Process the save results.
         // Indicates success
         return true;
      else {
         Database.Error err = sr.getErrors()[0];
         if(err.getStatusCode() == StatusCode.FIELD_FILTER_VALIDATION_EXCEPTION  &&  
            // Indicates success.
            return true;
            // Indicates failure.
            return false;
nikita dhamalnikita dhamal
@ naresh m getting same error "Entity is not org-accessible" in the trigger
piyush parmarpiyush parmar
Hi Nikita,
Project__Share projshr  = new Project__c();

insted of

​ Project__Share projshr  = new Project__Share ();

Naresh YadavNaresh Yadav
Hi Nikita 

Use this
Project__Share pro = new Project__Share();