+ Start a Discussion
Somasundaram S 1Somasundaram S 1 

error in test class please suggest me

    I got below error and i have given trigger and also test class , could you please suggets me 
System.DmlException: Update failed. First exception on row 0 with id a0i4E000000t7jmQAA; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, cus: execution of AfterUpdate
caused by: System.NullPointerException: Argument cannot be null
Trigger.cus: line 10, column 1: [] 
Stack Trace Class.Testcus.testingCus: line 40, column 1 

trigger cus on Sample_Transaction__c(after update) {
    Call2__c Objopp;
    Map<Id,Sample_Transaction__c> o = new Map<Id,Sample_Transaction__c>();
    o = trigger.oldMap;
        for (Sample_Transaction__c objCustomer: Trigger.new) {
       if (objCustomer.Status__c== 'Active') {
       if(objCustomer.Status__c!= o.get(objCustomer.Id).Status__c) {
       List<String> s = new List<String>{objCustomer.Call_ID__c};
        ApexPages.StandardController controller = new ApexPages.standardController(Objopp);
     UnlockRecordDuringApprovalCon ObjUnlock= new UnlockRecordDuringApprovalCon(controller);
                      for(Call2__c c: [SELECT id FROM Call2__c WHERE Name IN :s]){
                                     ObjUnlock.processRecord(c.id );

test class

private class Testcus {
    static testMethod void testingCus(){

Account TestOpp=new Account();
        insert TestOpp;
        Call2__c Testcall =new Call2__c();
        insert Testcall ;
        Address__c testadd = new Address__c();
        insert testadd;

        Sample_Lot__c testsample=new Sample_Lot__c();

          insert  testsample;
        Product__c testprod = new Product__c();
        insert testprod;
            Sample_Transaction__c testapp1 = new Sample_Transaction__c();
           testapp1.Account_ID__c =TestOpp.id;
       testapp1.Address_ID__c= testadd.id;
testapp1.Product__c= testprod.id;

insert testapp1;
        testapp1.Status__c = 'Saved';
        update testapp1 ;


In this line ApexPages.StandardController controller = new ApexPages.standardController(Objopp);
You are passing "Objopp" which is null in the trigger .

Please correct this.

Ashlekh Gera
karthikeyan perumalkarthikeyan perumal

Can you please post your "UnlockRecordDuringApprovalCon " page code  so that i can check that you need stadardcontroller (ApexPages.StandardController controller = new ApexPages.standardController(Objopp);) this line or not..