I am getting a System.NullPointerException: Attempt to de-reference a null object
in the last line (the one with the return) of the following code.
...
AggregateResult result = getResult(...);
Decimal value = (Decimal) result.get(fieldName);
return (value == null) ? 0 : value;
}
This really sounds strange to me aas I just added this line to prevent Nullreference errors. As this code is - let me called it - hard to debug I need to analyse this in my head and not in the IDE ;)
I can only think of two3 error sources that would throw other errors:
AggregateResult result
is null -> Would throw an error in the line above.- fieldName does not exist on on
result
-> Would also throw an error in the line above - Value can not be casted into a
Decimal
-> Would show different Exception
Might this be be a side effect of code in the return
statement?!