+ Start a Discussion
Bhola VishwakarmaBhola Vishwakarma 

error explanation for Testclasses


private class GoalControllerTest {

static Account acc;

public static void testData(){
       acc=new Account(LastName='ABC',FirstName='PQR',RecordTypeId='01220000000DnK3AAK');
       upsert 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;

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:

private class GoalControllerTest {
public static void testData(){
       Account acc = new Account(LastName='ABC',FirstName='PQR',RecordTypeId='01220000000DnK3AAK');
       upsert 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;



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?....