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
Mack DsozaMack Dsoza 

need Error solution

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

I am getting above error while executing the below query on system log...

 

GoalAssetAssociation__c a = new GoalAssetAssociation__c();

a.Goal__c = 'a0HN0000000lMhDMAU';

a.GoalYearValue__c=2015.0;

update a; OR upsert a;

 

GoalYearValue__c if a field of type number with numeric value of 16 & decimal value is of 2.

 

Please tell me how can i store value in it...Since I am getting above error....


Bramha1Bramha1

Hi,

 

  what datatype is the other field your are inserting. Is your Goal__c  a Number data type, but your passing a string in it.

try with 

 

 

 

 

GoalAssetAssociation__c a = new GoalAssetAssociation__c();

a.Goal__c = 1234;

a.GoalYearValue__c=2015.0;

insert a ;

 

 

cheers 

 

Bramha

 

Mack DsozaMack Dsoza

Actually, Goal__c is Lookup field which stores Id of my another object but in my record all values coming properly but only GoalYearValue__c is not coming bcoz of that I tried to insert value in that but I got an error which I have mentioned...

 

Please tell me, since it is of Type Number then why it is not accepting this value...

 

In Debug Log, I am getting this error ,

14:48:14.241 (241733000)|EXCEPTION_THROWN|[466]|System.NullPointerException: Attempt to de-reference a null object

14:48:14.241 (241551000)|METHOD_ENTRY|[460]|01pN00000004EQf|GoalMappingBean.populateGoalAseetMapping(Object, String, Double,)
14:48:14.241 (241695000)|SYSTEM_METHOD_ENTRY|[466]|Decimal.doubleValue() 
Bramha1Bramha1

Hi,

 

 if that is a look up to another Object, you need to create the other object first and pass it id in it. Check below:

 

 

This is your Other Object:

 

Object1__c obj1 = new Object1__c();

obj1.FiledName__c = 'Hello' ;

insert obj1 ;

 

 

And when you come to insert your new GoalAssetAssociation__c  Object ,

 

 

GoalAssetAssociation__c a = new GoalAssetAssociation__c();

a.Goal__c = obj1.Id;

a.GoalYearValue__c=2015.0;

insert a ;

 

You need the Lookup record to be already created and then pass the Id of the record.

 

 

Cheers

 

Bramha


 

Mack DsozaMack Dsoza

Sorry, My apologise for mistake,

Goal__c has masterdetail relationship with my another custom object....

& whatever u are guiding me, I already tried that but still facing problem there....

Bramha1Bramha1

Can you give me the details of the other Object as well so that i can try here and send you the code. Even though it is in Master detail relationship, it will work. 

 

Cheers

 

Bramha