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
streetstreet 

Error in Testcase for below Trigger.

This is trigger:

 

trigger placement_enddate on AVTRRT__Placement__c (before insert) {

for(AVTRRT__Placement__c plc:trigger.new)
 {
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:

 

@isTest
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='standarduser@testorg.com',

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

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

timezonesidkey='America/Los_Angeles', username='standarduser@testorg.com');


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';

jb.AVTRRT__Start_Date__c=date.ValueOf('2012-03-16');
insert jb;    // Showing error here while running the testcase!!!

 

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


AVTRRT__Job_Applicant__c ja=new AVTRRT__Job_Applicant__c();
ja.AVTRRT__Job__c=jb.id;
ja.AVTRRT__Contact_Candidate__c=ct.id;
insert ja;

AVTRRT__Placement__c a=new AVTRRT__Placement__c();
a.AVTRRT__Start_Date__c=date.ValueOf('2012-03-16');
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
RonakPatel.ceRonakPatel.ce

Hi

Here one mistake is there.

Try to use triiger with After insert Event.

 

 

streetstreet

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!!!

RonakPatel.ceRonakPatel.ce

HI,

 

Is there any triiger or Validation rule on object AVTRRT__Job__c?

streetstreet

Yes, we do have.

RonakPatel.ceRonakPatel.ce

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

 

AVTRRT.Trigger_Job

 

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