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
RajeevlsHydRajeevlsHyd 

System.NullPointerException: Attempt to de-reference a null object - Error oN test class

I am getting the error in a test class : Test class saving without any error but while runnig the test class getting :

System.NullPointerException: Attempt to de-reference a null object  ..... higlighted in bold .. Any suggestions?

 

@isTest
public with sharing class ESO_NewController_Test{

 

public static testMethod void testQD(){


String AVRecord_Type = RecordHandler_GetRecordTypeId.getId(Class_RecordTypeNames.AVSRecord_Type, Schema.Sobjecttype.BigMachines__Quote__c.getName());
String ESRecord_Type_MA = RecordHandler_GetRecordTypeId.getId(Class_RecordTypeNames.ESRecord_Type_MA, Schema.Sobjecttype.Account.getName());
String ES_MARecord_Type = RecordHandler_GetRecordTypeId.getId(Class_RecordTypeNames.ES_MA_Record_Type, Schema.Sobjecttype.Opportunity.getName());

//Account Creation
Account a = new Account();
a.Name = 'Testing';
a.Type = 'Dummy';
a.RecordTypeId = ES_Account_Record_Type_MA ;
a.Segment__c = 'Major Accounts';
a.LocalDecision__c = 'Yes';
a.EmployeesDMinput__c = 100;
a.PRMethod__c = 'Accountant';
a.PR_Vendor__c = 'Access 1';
insert a;


//Opportunity Creation
Opportunity opp = new opportunity();
opp.Name = 'Test';
opp.Account.Id = a.id;
opp.RecordTypeId = ES_MARecord_Type;
opp.Type = 'Adjustment';
opp.LeadNew__c = 'Marketing';
opp.LeadDetail__c = 'Advertising';
opp.CloseDate = Date.Today();
opp.StageName = 'Gained access';
insert opp;
String oppId = opp.id;


BigM__c bm = new BigM__c();
bm.Name = '2013-5555';
bm.BigM__cTransaction_Id__c = '35035555';
bm.RecordTypeId = AVSRecord_Type;
bm.BigM__Account__c = accId;
bm.BigM__Status__c = 'Pending';
bm.BigMachines__Opportunity__c = oppId;
insert bm;

ApexPages.StandardController controller = new ApexPages.StandardController(bm);
ApexPages.CurrentPage().getParameters().put('rType','AVSRecord_Type');
ApexPages.CurrentPage().getParameters().put('Id',bm.Id);
ESO_NewController clsTest = new ESO_NewController(controller);
clsTest.getRedir();

//ApexPages.StandardController controller2 = new ApexPages.StandardController();
}

souvik9086souvik9086

It will be like this

 

@isTest
public with sharing class ESO_NewController_Test{

 

public static testMethod void testQD(){


String AVRecord_Type = RecordHandler_GetRecordTypeId.getId(Class_RecordTypeNames.AVSRecord_Type, Schema.Sobjecttype.BigMachines__Quote__c.getName());
String ESRecord_Type_MA = RecordHandler_GetRecordTypeId.getId(Class_RecordTypeNames.ESRecord_Type_MA, Schema.Sobjecttype.Account.getName());
String ES_MARecord_Type = RecordHandler_GetRecordTypeId.getId(Class_RecordTypeNames.ES_MA_Record_Type, Schema.Sobjecttype.Opportunity.getName());

//Account Creation
Account a = new Account();
a.Name = 'Testing';
a.Type = 'Dummy';
a.RecordTypeId = ES_Account_Record_Type_MA ;
a.Segment__c = 'Major Accounts';
a.LocalDecision__c = 'Yes';
a.EmployeesDMinput__c = 100;
a.PRMethod__c = 'Accountant';
a.PR_Vendor__c = 'Access 1';
insert a;


//Opportunity Creation
Opportunity opp = new opportunity();
opp.Name = 'Test';
opp.AccountId = a.id;
opp.RecordTypeId = ES_MARecord_Type;
opp.Type = 'Adjustment';
opp.LeadNew__c = 'Marketing';
opp.LeadDetail__c = 'Advertising';
opp.CloseDate = Date.Today();
opp.StageName = 'Gained access';
insert opp;
String oppId = opp.id;


BigM__c bm = new BigM__c();
bm.Name = '2013-5555';
bm.BigM__cTransaction_Id__c = '35035555';
bm.RecordTypeId = AVSRecord_Type;
bm.BigM__Account__c = accId;
bm.BigM__Status__c = 'Pending';
bm.BigMachines__Opportunity__c = oppId;
insert bm;

ApexPages.StandardController controller = new ApexPages.StandardController(bm);
ApexPages.CurrentPage().getParameters().put('rType','AVSRecord_Type');
ApexPages.CurrentPage().getParameters().put('Id',bm.Id);
ESO_NewController clsTest = new ESO_NewController(controller);
clsTest.getRedir();

//ApexPages.StandardController controller2 = new ApexPages.StandardController();
}

 

If this post is helpful please throw Kudos.If this post solves your problem kindly mark it as solution.

Thanks

TwanTwan