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
pavan kumar 1864pavan kumar 1864 

Formula field not accesible in Test Class

Hi, i have put up a condition in class using Formula Field and now in the test class i want to use it For unit Testing,If i give the value to Formula Filed  the Error is popping up as this is NON- WRITTEABLE...what is the workaroud for this
Best Answer chosen by pavan kumar 1864
Suraj Tripathi 47Suraj Tripathi 47

Hi pavan,

You your formula filed is like

formula name Total

field Name1: Data1

field Name2: Data2

Formula

Total=Data1+Data2;

so you need to fill the value of Data1 and Data2 in test class after that it automatically calculated in Total

No need to assign value in total

Thanks Please mark it as the Best Answer

Thank You

All Answers

Suraj Tripathi 47Suraj Tripathi 47

Hi pavan,

You your formula filed is like

formula name Total

field Name1: Data1

field Name2: Data2

Formula

Total=Data1+Data2;

so you need to fill the value of Data1 and Data2 in test class after that it automatically calculated in Total

No need to assign value in total

Thanks Please mark it as the Best Answer

Thank You

This was selected as the best answer
AbhinavAbhinav (Salesforce Developers) 
Hi Pavan,

I think you are trying to populate formula field in testClass, please note it will populate automatically.

check this link
https://salesforce.stackexchange.com/questions/198345/field-is-not-writeable

If you need to acess formulaField in test class you need to re query it.

https://stackoverflow.com/questions/36718501/salesforce-formula-field-always-equals-null-in-apex-code

https://salesforce.stackexchange.com/questions/129500/formula-field-is-not-getting-executed-in-test-class

If it helps, please mark this as best answer.

Thanks!