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

Entity is not org-accessible in apex trigger

I am getting a save error with entity not org-accesible for my trigger below. 


trigger InterviewerPickerTrigger on Interviewer__c (after insert, before delete, after delete) {
if (Trigger.isInsert){
List<Review__c> reviews = new List<Review__c>();
List<Job_Application__Share> jobAppShares = new List<Job_Application__Share>();
List<Candidate__Share> candidateShares = new List<Candidate__Share>();
List<ID> positionIds = new List<ID>();

// get a list of all the position ids
System.debug('*****************the interviewer record: ' + i);

// select all the job apps associated to those positions
List<Job_Application__c> jobApps = [select,j.position__c,j.candidate__c,j.candidate__r.ownerid from Job_Application__c j where j.position__c IN :positionIds];

// loop thru all the jobApps we just retrieved
for(Job_Application__c jobApp:jobApps){
if (i.Position__c == jobApp.Position__c){
// create the new review sobject
Review__c review = new Review__c();
review.Interviewer__c = i.Id;
review.Job_Application__c = jobApp.Id;
// create the jobApp share sobject ONLY if the interviewer is not the owner of the job app
if (i.employee__c != jobApp.ownerid){
Job_Application__Share jobAppShare = new Job_Application__Share();
jobAppShare.ParentId = jobApp.Id;
jobAppShare.UserOrGroupId = i.Employee__c;
jobAppShare.AccessLevel = 'Edit';
// now the candidate share sobject ONLY if the interviewer is not the owner of the candidate
if (i.employee__c != jobApp.candidate__r.ownerid){
// make sure there is a candidate on the Job App
if (jobApp.candidate__c != null){
Candidate__Share candidateShare = new Candidate__Share();
candidateShare.ParentId = jobApp.candidate__c;
candidateShare.UserOrGroupId = i.Employee__c;
candidateShare.AccessLevel = 'Read';
// now create the incomplete reviews for the interviewers
insert reviews;

// now share the job apps and candidates with the interviewer
System.debug('***candidateShares=' + candidateShares);
insert candidateShares;
System.debug('***jobAppShares=' + jobAppShares);
insert jobAppShares;

} else if (Trigger.isDelete){
if (Trigger.isBefore){
// first remove the reviews associated to the interviewer **only if they are not already completed
Map<ID,Interviewer__c> iMap = Trigger.oldMap;
List<Review__c> reviews = [select id,job_application__c,interviewer__c from review__c where interviewer__c IN :iMap.keySet() and review_completed__c != true];
delete reviews;
} else if (Trigger.isAfter){
// now remove the sharing from the old interviewer on the Job App and Candidate


Thiyagarajan SelvarajThiyagarajan Selvaraj

Change the object sharing model of the Job application to private. I hope this solves your issue.