1

I have created a simple object called Object__c. Also Number field (18,0) I have created for this object called Number__c. Then I have created one record with name 'x' and Number__c value of '111 111 111 111 111 111'. When I do an aggregate query 'select SUM(Number__c) from Object__c' I receive '111111111111111100' instead of expected '111111111111111111'.

Can anyone explain to me why two last digits are discarded during SalesForce aggregate query?


Interesting thing: when I query from query explorer, both usual and aggregated query return '111111111111111100' instead of expected '111111111111111111'.

Usual Query Aggregated Query

However, when I put this into a trigger,

System.debug(LoggingLevel.ERROR, '@@@ trigger.new[0].Number__c: ' + trigger.new[0].Number__c );
System.debug(LoggingLevel.ERROR, '@@@ select.new[0].Number__c: ' + [ select number__c from Object__c where Id = :trigger.new[0].Id ].Number__c );
System.debug(LoggingLevel.ERROR, '@@@ select.SUM(number__c): ' + [ select SUM(number__c) from Object__c where Id = :trigger.new[0].Id ][0].get('expr0') );

and clone or edit the record, it shows correct value '111111111111111111' for usual query but wrong value '111111111111111104' for aggregated query

enter image description here

The most interesting part is that wrong value from trigger is different (by 4) from wrong value from query explorer results.

1 Answer 1

0

People say that aggregate query must have converted the value to double, doing so, it is losing precision (16 correct digits left out of 18).

You must log in to answer this question.

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