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
Rahul Bhattad 4Rahul Bhattad 4 

Formula field values not reflecting in Test class

I have trigger on Before Update event that calls a method of class with Set of IDs as input parameter. In the class I am fetching the details of couple of formula field based on Id that I have passed and then doing some opertation based on different values of these two formula fields. I have tested manually the funtionality and it's working as expected.

Now the issue is with Test Class. I have called this Class after I have  setup the data but in Raw Logs the values of these two formula field is coming 0.00.

I have used Formula.recalculateFormulas method as well between start and stop test and then called the method of the class. In Debug I can see the values correctly calculated by Formula.recalculateFormulas but once it calls the class and it's method, I can see values as 0.00 only. I am not sure what do I need to do in order to have these calculated values of formula once Test class calls the method
SarvaniSarvani
Hi Rahul,

In your test class when you are setting up the data did you input data so that formula field can have value other than 0 ? Are you checking the formula field value after performing Insert/Update operation ?

Please go through the link:
https://developer.salesforce.com/forums/ForumsMain?id=906F00000008miOIAQ

If the problem still persists please try to provide your trigger and test class.

Hope this helps!

Thanks
Rahul Bhattad 4Rahul Bhattad 4
Hi Sarvani,

Yes, I have added the input data that should calculate the formula and give non zero output. As I said, I have used Formula.recalculateFormulas method and checked the values and they were correctly calculated. Not sure why they are coming as 0 when I call the method of the class that I want to Test.