• deepa deshpande 15
  • NEWBIE
  • 0 Points
  • Member since 2020

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 1
    Replies
Hi Team,

Can someone help me to resolve the below error in test class.

System.NullPointerException: Attempt to de-reference a null object
Stack TraceClass.CtrlCallReport.save: line 912, column 1
Class.CtrlCallReport_Test.createNew: line 1315, column 1
Below is my code.

test.startTest();

            //first test (insert)
            PageReference pageRefInsert = new PageReference('/apex/Product_Pre_Population');
            Test.setCurrentPage(pageRefInsert);
            ApexPages.currentPage().getParameters().put('con', callrep.Contact1__c);
            ApexPages.currentPage().getParameters().put('org', callrep.Organisation__c);
            ApexPages.currentPage().getParameters().put('plan1', callrep.Prio_1_Planned_Objectives__c);
            ApexPages.currentPage().getParameters().put('plan2', callrep.Prio_2_Planned_Objectives__c);
            ApexPages.currentPage().getParameters().put('plan3', callrep.Prio_3_Planned_Objectives__c);
            ApexPages.currentPage().getParameters().put('plan4', callrep.Prio_4_Planned_Objectives__c);
                
            // Open Custom Controller
            ApexPages.StandardController ExtControllerInsert = new ApexPages.StandardController(callrep);
                        
            // Open extension
            CtrlCallReport cr = new CtrlCallReport(ExtControllerInsert);

            //just to cover this methods but as far as I know these are not being used
            CtrlCallReport.TestRemote('test');
            Task pTask = CtrlCallReport.CreateNewTask(string.valueOf(system.today().month() + '/' + system.today().day() + '/' + system.today().year() ), 'test subject', callrep.Id, 'false', String.valueOf(org.Id), String.valueOf(cust.Id));
            Task temptask = [SELECT Id, Subject FROM Task WHERE Id = : pTask.Id];
            System.assertEquals('test subject', temptask.Subject);
            CtrlCallReport.LoadAddedTasks(String.valueOf(callrep.Id));

            cr.save();
i wrote a test class to test a trigger and future apex class, nevertheless i am reciving this error message, can anyone help me out

System.DmlException: Update failed. First exception on row 0 with id 00Q260000034xE0EAI; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, CP_Approve_Rejects: execution of AfterUpdate

caused by: System.NullPointerException: Attempt to de-reference a null object

Trigger.CP_Approve_Rejects: line 9, column 1: []


Test class code as below
@isTest
private class CP_Approve_Reject_Test {
    static testmethod void  Approve_CP_Lead() {              
        // This causes a fake response to be generated
         Lead lead = new Lead(firstName='first', lastName='last', company='company', leadSource='Client-Portal-Lead-Cn', entity__c='Hong Kong', isTest__c=true);
      
        
              
              
        Test.startTest();
         insert lead;
          Lead leads = lead;
         leads.Approval_Status__c ='Approved';
         update(leads);
        Test.setMock(WebServiceMock.class, new ADSSWebServicesMockImpl());
         
        // Test.setMock(WebServiceMock.class, new ADSSWebServicesMockImpl());
        
        Test.stopTest();

    }
    
    }