+ Start a Discussion
The new LearnerThe new Learner 

How to calculate the formula in the test class

Hi Experts,

Below is the formula field which i need o cover the in the test class but i am not able to do that kindly help me out.
Current_Week__c is formula field  which we have (IF( 
CEILING( (TODAY() - DATE ( YEAR(TODAY()), 1, 1) + 1) / 7) > 52, 
52, 
CEILING( (TODAY() - DATE( YEAR(TODAY()), 1, 1) + 1) / 7) 
))
below is calculation which i am doing in the class.
 decimal currentweek=a.Current_Week__c/a.Call_List_Frequency__c;
 if(currentweek.scale()<0)

 
Raj VakatiRaj Vakati
Formula fields are automatically calculated in test classes also you no need to do any manipulates .. 

just set the data accordingly 
Jolly_BirdiJolly_Birdi

Hi
Check this below Code:

Date todayDate = Date.today();
Date startYearDate = Date.newInstance(Date.today().year(),1,1);
decimal differenceBetweenTwoDates = Math.Ceil(startYearDate.daysBetween(todayDate)/7);
if(differenceBetweenTwoDates>52.0)
    differenceBetweenTwoDates = 52.0;
 



Please mark this as best answer if you find it positive.
Thanks
Jolly Birdi