You need to sign in to do that
Don't have an account?
Amit Jadhav 13
How to cover formula field inside formula field in test class
for example
Price__c * Qyt__c = Total_Price__c (Total price is formula field)
Total_Price__c * Disscount_per__c = Disscount__c (Disscount Is also formula field)
Disscount__c + Total_Price__c = Amount (Amount is also formula field)
how to cover this filed in test class
Price__c * Qyt__c = Total_Price__c (Total price is formula field)
Total_Price__c * Disscount_per__c = Disscount__c (Disscount Is also formula field)
Disscount__c + Total_Price__c = Amount (Amount is also formula field)
how to cover this filed in test class
When we are working with formula fields, In test class there is no need to insert a record with that particular field and also you cannot insert that record with the formula field.
You need to just insert the record with fields that are used in the formula field.
As in your case,
Price__c * Qyt__c = Total_Price__c (Total price is formula field)
We insert a record with Price__c and Qyt__c and as you said,
Total_Price__c * Disscount_per__c = Disscount__c
This is also a formula field so you have to insert that record with Disscount_per__c field also.
Thanks,
Ajay Dubedi
All Answers
BTW you can try to retrieve a record and then add an assertion for each field checking for the expected result.
You have to just create Price__c and Qyt__c for creating Total_Price__c.
So to cover Total_Price__c in test class insert record with Price__c and Qyt__c field, so Total_Price__c will automatically create.
And same as others.
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks,
Ajay Dubedi
Total_Price__c * Disscount_per__c = Disscount__c (Disscount Is also formula field)
When we are working with formula fields, In test class there is no need to insert a record with that particular field and also you cannot insert that record with the formula field.
You need to just insert the record with fields that are used in the formula field.
As in your case,
Price__c * Qyt__c = Total_Price__c (Total price is formula field)
We insert a record with Price__c and Qyt__c and as you said,
Total_Price__c * Disscount_per__c = Disscount__c
This is also a formula field so you have to insert that record with Disscount_per__c field also.
Thanks,
Ajay Dubedi