+ Start a Discussion
sasya.ravisasya.ravi 

In my test class i am unable to cover the formula field.

i need quick help,
In my test class i am unable to cover the formula field.

I have a formula field Approved__C in opportunity object.That formula field holding the quote object field value ApprovalStatus__c.
i am inserting data in Quote object along with writeable field ApprovalStatus__c, but still i am not able to getting data into Opportunity formula field still it is showing null value.

 
veda shriveda shri
Hi Sasya,

Please cross check the Quote.ApprovalStatus__c field is having value asfter insert.

Thanks,
vedashri
sasya.ravisasya.ravi
Yes Veda , It is having the value.
Vasani ParthVasani Parth
Sasya,

Just While inserting data in the test class.please insert the field which give the out put of formula.
Ex:-field a+field b= field c(Formula field).

Ur test method will be like this :-
object o=new object(o.filed a=10,o.field b=20);
insert o;
It automatically covers the formula.

Please mark this as the best answer if this helps
veda shriveda shri
Hi Sasya,

How you are checking 'Approved__C ' field having value or not?

You need to query opprtunity after inserrt/update of opprtunity/Quote record. Then only you will get updated value.

Can you please check and let me know?
 
veda shriveda shri
Hi,

Are you able to slove the issue? please let me know if any help.

Thanks,
Vedashri
Ishwar ShindeIshwar Shinde
Agreed. If you are using assert statement to verify the formula value, please make new SOQL query just before you need formula field. Current instance of object is not updated even if formula has value to display. You need to make query in database to get latest value.