Sales Force Automation | Calculating the Week Number

Sales Force Automation : In our previous salesforce Tutorial we have learned about How to Derive Year and Month value for Opportunity Close Date. In this salesforce Training Tutorial we are going to learn about Calculating week number for the Opportunity Close date.

Sales Force Automation 

Here we calculating week number according to the opportunity Close date. Week number is calculated by using Standard Date field called CloseDate.

Go to Setup=>Customize=>Opportunity=>Fields.

Deriving year and month values from the opportunity close date using a formula

Go to Opportunity Custom Fields and Relationships Section.

Deriving year and month values from the opportunity close date using a formula2

Select New Button.

sales Force automation example

Select Formula as Data Type and select next button.

salesforce automation

Sales Force Automation

 Enter Field Label as Close Date Week Number. When we click on Field name text box it will be automatically filled with field label.

Select Formula return type as Number as shown above and make sure decimal places will be to Zero.

Now select Next Button.

salesforce automation

Sales Force Automation

  • Take Sunday as reference point.
  • Calculate difference between reference point and close date.
  • Divide the difference number with 7 (Changing days to weeks).
  • Floor function removes any decimal places and gives whole no of weeks.
  • Mod function gives Modulus of 52 and retain the remainder weeks.
  • Finally the calculation is incremented by 1 which gives starting week number.

=> Treat Blank Fields as Zero.

Now click on Next Button.

In Establish Field-Level Security select visible to every profile.

Finally select Save Button.

Testing the Code

Go to any opportunity page and open Opportunity record in detailed view and we can observe Close Date Week Numbers as below.

salesforce automation

salesforce automation

Leave a Reply