You need to sign in to do that
Don't have an account?
Sarada RVS 2
Critical Issue : System.NullPointerException: Attempt to de-reference a null object
Hi,
I am unable to deploy my code due to null pointer exception.
Could anyone help me please.
Below is the my controller and test class.
Controller wit the method iam testing
public PageReference saveTOLead()
{
showrefreshblck = true;
shouldRedirect = true;
Lead acc = new Lead(id=a.id);
redirectUrl = controller.view().getUrl();
getRatings(acc.Id,allCompDetails[selectedrow].companyId);
acc.Company_Registration_Number__c = allCompDetails[selectedrow].RegistrationNumber;
acc.Company = allCompDetails[selectedrow].Company;
acc.is_saved_prev__c = true;
acc.Company_Id__c = allCompDetails[selectedrow].companyId;
List<String> addrArray = allCompDetails[selectedrow].Address.split(',');
Map<Integer,String> accMap = new Map<Integer,String>();
Integer n= addrArray.size();
for(Integer l=0;l<addrArray.size();l++)
{
accMap.put(l, addrArray[l]);
}
acc.Street = accMap.get(0);
acc.City = accMap.get(1);
acc.State = accMap.get(2);
acc.PostalCode = allCompDetails[selectedrow].postalCode;
acc.Company_Status__c = allCompDetails[selectedrow].status;
acc.CompanyType__c =allCompDetails[selectedrow].type;
showPgblck = false;
return null;
}
Test class witht the piece which testes the method
public static testMethod void testLeadRatings() {
Test.setMock(HttpCalloutMock.class, new MockHttpResGenFetchLeadDetailsRatings());
Lead l = new Lead();
l.FirstName = 'FirstName1';
l.LastName = 'LastName1';
l.MobilePhone = '074434567890';
l.Company = 'Traves1';
insert l;
test.startTest();
PageReference pageRef = Page.Lead_DisplayCompany; //FC_VF
Test.setCurrentPage(pageRef);
pageRef.getParameters().put('id',l.id);
ApexPages.StandardController sc = new ApexPages.StandardController(l);
LeadFetchCompanyDetails fc = new LeadFetchCompanyDetails(sc);
LeadFetchCompanyDetails.CompanyDetails cd = new LeadFetchCompanyDetails.CompanyDetails();
cd.companyid = 'GB003/0/07375960';
cd.RegistrationNumber='07375960';
cd.Address = 'Test.test,test';
cd.Company = 'Traves';
cd.postalCode ='HA02RX';
cd.Status ='Active';
cd.Type= 'Ltd';
fc.allCompDetails.add(cd);
// fc.selectedrow = 0;
system.assert(fc!=null);
fc.saveTOLead();
LeadFetchRatingDetails.CompanyDetails lfrd = new LeadFetchRatingDetails.CompanyDetails ();
LeadFetchRatingDetails.contactWrapper cw = new LeadFetchRatingDetails.contactWrapper();
test.stopTest();
}
I am unable to deploy my code due to null pointer exception.
Could anyone help me please.
Below is the my controller and test class.
Controller wit the method iam testing
public PageReference saveTOLead()
{
showrefreshblck = true;
shouldRedirect = true;
Lead acc = new Lead(id=a.id);
redirectUrl = controller.view().getUrl();
getRatings(acc.Id,allCompDetails[selectedrow].companyId);
acc.Company_Registration_Number__c = allCompDetails[selectedrow].RegistrationNumber;
acc.Company = allCompDetails[selectedrow].Company;
acc.is_saved_prev__c = true;
acc.Company_Id__c = allCompDetails[selectedrow].companyId;
List<String> addrArray = allCompDetails[selectedrow].Address.split(',');
Map<Integer,String> accMap = new Map<Integer,String>();
Integer n= addrArray.size();
for(Integer l=0;l<addrArray.size();l++)
{
accMap.put(l, addrArray[l]);
}
acc.Street = accMap.get(0);
acc.City = accMap.get(1);
acc.State = accMap.get(2);
acc.PostalCode = allCompDetails[selectedrow].postalCode;
acc.Company_Status__c = allCompDetails[selectedrow].status;
acc.CompanyType__c =allCompDetails[selectedrow].type;
showPgblck = false;
return null;
}
Test class witht the piece which testes the method
public static testMethod void testLeadRatings() {
Test.setMock(HttpCalloutMock.class, new MockHttpResGenFetchLeadDetailsRatings());
Lead l = new Lead();
l.FirstName = 'FirstName1';
l.LastName = 'LastName1';
l.MobilePhone = '074434567890';
l.Company = 'Traves1';
insert l;
test.startTest();
PageReference pageRef = Page.Lead_DisplayCompany; //FC_VF
Test.setCurrentPage(pageRef);
pageRef.getParameters().put('id',l.id);
ApexPages.StandardController sc = new ApexPages.StandardController(l);
LeadFetchCompanyDetails fc = new LeadFetchCompanyDetails(sc);
LeadFetchCompanyDetails.CompanyDetails cd = new LeadFetchCompanyDetails.CompanyDetails();
cd.companyid = 'GB003/0/07375960';
cd.RegistrationNumber='07375960';
cd.Address = 'Test.test,test';
cd.Company = 'Traves';
cd.postalCode ='HA02RX';
cd.Status ='Active';
cd.Type= 'Ltd';
fc.allCompDetails.add(cd);
// fc.selectedrow = 0;
system.assert(fc!=null);
fc.saveTOLead();
LeadFetchRatingDetails.CompanyDetails lfrd = new LeadFetchRatingDetails.CompanyDetails ();
LeadFetchRatingDetails.contactWrapper cw = new LeadFetchRatingDetails.contactWrapper();
test.stopTest();
}
Does the null pointer exception only occur when running the test code? If so, you could run the test manually (from the Apex Test Execution page) and you should be able to get the class name and line number where the exception was thrown - as well as the whole call stack. Could you do that and post the results?