public class Incrementtrigger_update_Test 
    Public Static TestMethod Void Test1()
        SCSCHAMPS__Appointment__c app =new SCSCHAMPS__Appointment__c(CTC_Offered__c = 12.00,Pre_CTC__c = 12.00,Prop_CTC__c=12.00);
        Insert app;
        System.AssertNotEquals(Null, app.Id);

        Appraisal__c Apprase  =  new Appraisal__c (Appointments__c= App.Id , Status_of_Apprisal__c= 'Yes',Amount_Incremented__c=24,of_Increment__c=24 );
        System.AssertNotEquals(Null, Apprase.Id);
        SCSCHAMPS__Appointment__c ap =new SCSCHAMPS__Appointment__c(CTC_Offered__c = 12.00,Pre_CTC__c = 12.00,Prop_CTC__c=12.00);
        Insert ap;
        System.AssertNotEquals(Null, ap.Id);

        Appraisal__c Appr  =  new Appraisal__c (Appointments__c= App.Id , Status_of_Apprisal__c = 'No',Amount_Incremented__c=24,of_Increment__c=24 );
        System.AssertNotEquals(Null, Appr.Id);

  • 4
    insert Appr; before System.AssertNotEquals(Null, Appr.Id); and insert Apprase; before System.AssertNotEquals(Null, Apprase.Id); – Saumya Ranjan Satapathy May 31 '16 at 12:35
  • 1
    @SaumyaRanjanSatapathy You should post that as the answer to the question. – crmprogdev May 31 '16 at 12:47

Id for a new object is created once it is persisted to database. As in your code you are checking for not null Id before inserting the object, so the assert statements are failing.

You can try this to avoid the exception;

//line 12
insert Apprase; 
System.AssertNotEquals(Null, Apprase.Id);
//line 18 insert Appr; System.AssertNotEquals(Null, Appr.Id);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.