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

Error in Testcase for below Trigger.

This is trigger:


trigger placement_enddate on AVTRRT__Placement__c (before insert) {

AVTRRT__Job_Applicant__c japp=[select AVTRRT__Job__r.AVTRRT__Estimated_Close_Date__c from AVTRRT__Job_Applicant__c where id=:plc.AVTRRT__Job_Applicant__c ];
plc.AVTRRT__End_Date__c =japp.AVTRRT__Job__r.AVTRRT__Estimated_Close_Date__c;




Here Is the Testcase below:


private class placement_enddate_TC

static testMethod void myUnitTest()

Profile p = [select id from profile where name='Standard User'];

User u = new User(alias = 'standt', email='',

emailencodingkey='UTF-8', lastname='Testing', languagelocalekey='en_US',

localesidkey='en_US', profileid = p.Id,

timezonesidkey='America/Los_Angeles', username='');

account acct=new account();
acct.Name='Test account';
insert acct;


AVTRRT__Job__c jb=new AVTRRT__Job__c();
jb.AVTRRT__Job_Title__c='Test Functional';

insert jb;    // Showing error here while running the testcase!!!


contact ct=new contact(); = '012D0000000hW06';
ct.LastName='test candidate';
insert ct;

AVTRRT__Job_Applicant__c ja=new AVTRRT__Job_Applicant__c();;;
insert ja;

AVTRRT__Placement__c a=new AVTRRT__Placement__c();
insert a;


Method NameTotal Time (ms)MessageStack Trace

placement_enddate_TC.myUnitTest234.0System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, AVTRRT.Trigger_Job: execution of BeforeInsert caused by: System.NullPointerException: Attempt to de-reference a null object (AVTRRT): []Class.placement_enddate_TC.myUnitTest: line 28, column 1


Here one mistake is there.

Try to use triiger with After insert Event.




If im going for After insert the record is not getting updated, its saying that record is Read only.


When Using before insert trigger working fine, But problem in testcase!!!




Is there any triiger or Validation rule on object AVTRRT__Job__c?


Yes, we do have.


Then Check that trigeer or Validation Rule
Make The Object Record According to That Critera
Error is not in Test class But In that Trigeer/ 

Jerun JoseJerun Jose

Hi your trigger and test class look fine to me.


From the error message It looks like the error is due to another piece of code




If I am right, Trigger_Job is a method in AVTRRT class which is causing the problem.