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
Bhola VishwakarmaBhola Vishwakarma 

error explanation for Testclasses

@isTest

private class GoalControllerTest {

static Account acc;

public static void testData(){
       acc=new Account(LastName='ABC',FirstName='PQR',RecordTypeId='01220000000DnK3AAK');
       upsert acc;
       system.assertNotEquals(null,acc);
       Entity_Global_Assumption__c ega=new Entity_Global_Assumption__c(Account__c=acc.id,Expected_Return_on_Investment__c=30,Income_Growth_Rate__c=3,Inflation_Rate__c=6,Number_Of_Months__c=5);
       upsert ega;
       system.assertNotEquals(null,ega.id);


i am placeing a piece of my code that gives an error

System.nullpointer Exception Attempt to derefrence null object

what could be the possible reason for that 

so where should i check

Rahul SharmaRahul Sharma

is there any specific reason that you are creating a static variable?

if not, then change your code to:

@isTest
private class GoalControllerTest {
public static void testData(){
       Account acc = new Account(LastName='ABC',FirstName='PQR',RecordTypeId='01220000000DnK3AAK');
       upsert acc;
       system.assertNotEquals(null,acc);
       Entity_Global_Assumption__c ega=new Entity_Global_Assumption__c(Account__c=acc.id,Expected_Return_on_Investment__c=30,Income_Growth_Rate__c=3,Inflation_Rate__c=6,Number_Of_Months__c=5);
       upsert ega;
       system.assertNotEquals(null,ega.id);

 

kiranmutturukiranmutturu

i think information if you can post the complete code and error then its easy to track.. from the above code i can't understand how u r creating an account with the fields lastname and firstname.. those are not in account right?....