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.
Go to Opportunity Custom Fields and Relationships Section.
Select New Button.
Select Formula as Data Type and select next button.
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.
- 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.