0

I am getting the mentioned error in the following line:

map1.get(PAPC.Country__c).Q1__c += (PAPC.Q1FX__c == null ? 0.0 : PAPC.Q1FX__c); 

Baically it's assigning value from one object to the other. Q1FX__c can be zero at times .

Please help me understand why the error , since I'm encountering it for the first time.

4
  • Yes, but are you sure the value you want is in map1?
    – Jagular
    Mar 25, 2015 at 17:38
  • 2
    If any of these objects are null, you will get that error: map1, map1.get(PAPC.Country__c), PAPC, objPAPC Mar 25, 2015 at 17:45
  • Did you instantiate your map after diclaring? Mar 26, 2015 at 2:02
  • @Jagular Value will be getting assigned to field in map1 Mar 26, 2015 at 9:56

1 Answer 1

2

Its because one of your object is null, try this

if(map1 != null && PAPC != null && map1.get(PAPC.Country__c) != null && PAPC != null && objPAPC != null)
{
    map1.get(PAPC.Country__c).Q1__c += (PAPC.Q1FX__c == null ? 0.0 : objPAPC.Q1FX__c); 
}
7
  • 2
    Your guard will still throw an NPE if PAPC is null because you are checking PAPC.Country__c before you check PAPC
    – BarCotter
    Mar 25, 2015 at 16:04
  • 3
    Thats right @BarCotter, just edited code !!! Mar 25, 2015 at 16:05
  • Any reason why it's working in other sandbox environments and not working in Production? Mar 26, 2015 at 12:21
  • Is the data exactly the same in each environment?
    – Jagular
    Mar 26, 2015 at 13:23
  • May be you are initializing your objects if it finds any record. And there is no record as per condition in your code. Mar 26, 2015 at 16:01

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .