• Daniel143
  • NEWBIE
  • 0 Points
  • Member since 2013

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 2
    Replies

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
for(Interviewer__c i:Trigger.new){
System.debug('*****************the interviewer record: ' + i);
positionIds.add(i.Position__c);
}

// select all the job apps associated to those positions
List<Job_Application__c> jobApps = [select j.id,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){
for(Interviewer__c i:Trigger.new){
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;
reviews.add(review);
// 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';
jobAppShares.add(jobAppShare);
}
// 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';
candidateShares.add(candidateShare);
}
}
}
}
}
// 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

}
}
}

I am trying to write a test class and getting a save error in line 0.

 

public with sharing class HelloWorldTestClass {
static testMethod void HelloWorldTest(){
List<Position__c> positions = new List<Position__c>();
for (Integer i=0; i < 20; i++){
Position__c p = new Position__c();
position__c.Name = 'testName' + i;
position__c.Job_Description__c = 'testDescription' + i;
positions.add(p);
}

try{
System.debug('Attempting to insert positions');
insert positions;
System.debug('Insert complete');
// refresh the Position list to include the Hello__c field after the insert
Map<ID,Position__c> positionMap = new Map<ID,Position__c>(positions);
positions = [select id,name,Hello__c from Position__c where id IN :positionMap.keySet()];
for (Position__c position:positions){
System.assertNotEquals(position.id,null);
System.assertEquals(position.Hello__c, 'World');
System.debug('position.id=' + position.id);
System.debug('position.name=' + position.name);
System.debug('position.Hello__c=' + position.Hello__c);
}
} catch (System.DmlException e){
System.debug('We caught a DML exception: ' + e.getDmlMessage(0));
}

}

}

I am trying to write a test class and getting a save error in line 0.

 

public with sharing class HelloWorldTestClass {
static testMethod void HelloWorldTest(){
List<Position__c> positions = new List<Position__c>();
for (Integer i=0; i < 20; i++){
Position__c p = new Position__c();
position__c.Name = 'testName' + i;
position__c.Job_Description__c = 'testDescription' + i;
positions.add(p);
}

try{
System.debug('Attempting to insert positions');
insert positions;
System.debug('Insert complete');
// refresh the Position list to include the Hello__c field after the insert
Map<ID,Position__c> positionMap = new Map<ID,Position__c>(positions);
positions = [select id,name,Hello__c from Position__c where id IN :positionMap.keySet()];
for (Position__c position:positions){
System.assertNotEquals(position.id,null);
System.assertEquals(position.Hello__c, 'World');
System.debug('position.id=' + position.id);
System.debug('position.name=' + position.name);
System.debug('position.Hello__c=' + position.Hello__c);
}
} catch (System.DmlException e){
System.debug('We caught a DML exception: ' + e.getDmlMessage(0));
}

}

}