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.

  • Yes, but are you sure the value you want is in map1? – Jagular Mar 25 '15 at 17:38
  • 2
    If any of these objects are null, you will get that error: map1, map1.get(PAPC.Country__c), PAPC, objPAPC – Jeremy Nottingham Mar 25 '15 at 17:45
  • Did you instantiate your map after diclaring? – Maruf Bagwan Mar 26 '15 at 2:02
  • @Jagular Value will be getting assigned to field in map1 – Vanilla_Sky Mar 26 '15 at 9:56
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); 
}
  • 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 '15 at 16:04
  • 3
    Thats right @BarCotter, just edited code !!! – Jitendra Zaa Mar 25 '15 at 16:05
  • Any reason why it's working in other sandbox environments and not working in Production? – Vanilla_Sky Mar 26 '15 at 12:21
  • Is the data exactly the same in each environment? – Jagular Mar 26 '15 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. – Jitendra Zaa Mar 26 '15 at 16:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.