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
chuk2chuk2 

Entity is not org-accessible in apex controller

I have a visualforce page that creates a new user and contact, I'm updating the controller class to also add a sharing rule for the new user. However, I am now getting the error "Entity is not org-accessible". I'm told this error is due to typing in an entity wrong, like only 1 _ or such but I simply can not find the typo in my code. Any help or ideas? 

 

here is the new code that is causing the error. 

 

 

Volunteer__Share vShare = new Volunteer__Share();
vShare.ParentId = vID; // The volunteer record that we need to give access to.
vShare.UserOrGroupId = u.Id; // The user to which access is being granted
vShare.AccessLevel = 'Edit';
vShare.RowCause = Schema.Volunteer__Share.RowCause.Contact__c;
Database.SaveResult insertResults = Database.insert(vShare,false); // The false parameter allows for partial processing if multiple records passed into the operation.
// Error handling - did the insert work as intended.
if(insertResults.isSuccess()){ // Indicates success
System.debug('Recrords for BookShare inserted successfully'); 
}

 

Best Answer chosen by Admin (Salesforce Developers) 
chuk2chuk2

I found an older post with the answer to my problem... The share records only exist when the object sharing model is set to private. All I had to do was change the sharing model for that object and the error disappeared. 

All Answers

chuk2chuk2

I found an older post with the answer to my problem... The share records only exist when the object sharing model is set to private. All I had to do was change the sharing model for that object and the error disappeared. 

This was selected as the best answer
kevingwynnkevingwynn
chuk2, thanks for that info! We were having the same error. We were getting: Error: Entity is not org-accessible (line 2, column 9) on a unit test class. The line/column gives no help as it points to the "class" keyword for some reason. Our deployment person failed to change an object from Public Read/Write to Private in the Sharing Settings before deploying this test class.

The issue was that we had changed the model in our dev sandbox and updated the code to create sharing rules via Apex in the test class, but the sharing model didn't get changed before attempting to deploy. So you are spot-on on what the problem is (Sharing objects do not exist if sharing model is not "Private").