A CRM system must help its users to be as productive as possible to justify its investment; therefore, if there are any aspects that can be made more efficient, it is usually worth considering.
The Salesforce CRM application aims to be as efficient as possible out of the box; however, there are often organization-specific business processes and rules that need to be implemented, and this is where the power of the Salesforce platform becomes truly apparent.
In this post, we have provided recipes to create business processes and automate data manipulation that can be used to satisfy an organization’s unique requirements for business rules and logic.
Deriving year and month values from an Opportunity close date using a formula
To simplify the format of dates for presentation and reporting, we can automatically derive the year and month from a date field that contains month, day, and year.
In this recipe, we will display a derived year and month text value for the opportunity close date on the opportunity record detail and edit pages calculated from the standard date field called CloseDate.
How to do it…
Carry out the following steps to create a formula field to derive year and month values from the opportunity close date for opportunity records:
- Click on the Setup gear icon in the top right-hand corner of the main Home page, as shown in the following screenshot:
2. Click on Setup, as shown in the following screenshot:
3. Navigate to the Opportunity customization setup page as follows:
Objects and Fields | Object Manager | Opportunity | Fields & Relationships.
Locate the Fields & Relationships section on the right of the page.
4. Click on New.
We will be presented with the Step 1. Choose the field type page.
5. Select the Formula option.
6. Click on Next.
We will be presented with the Step 2. Choose output type page.
7. Enter CloseDate YEAR MONTH in the Field Label textbox.
8. Click on the Field Name. When clicking out of the Field Label textbox the Field Name is automatically filled with the value Close_Date_Year_Month.
9. Set the Formula Return Type as Text.
10. Click on Next.
We will be presented with the Step 3. Enter formula page.
11. Paste or enter the following code in the formula editor box:
TEXT(YEAR(CloseDate)) & " " & CASE( MONTH(CloseDate), 1, "January", 2, "February", 3, "March", 4, "April", 5, "May", 6, "June", 7, "July", 8, "August", 9, "September", 10, "October", 11, "November", 12, "December", "Error!")
The formula field is to be set according to the following screenshot:
Optionally, enter details in the Description field.
12. Optionally, enter details in the Help Text field.
13. In the Blank Field Handling section, select the option Treat blank fields as blanks.
14. Click on Next.
We will be presented with the Step 4. Establish field-level security page.
15. Select the profiles to which you want to grant read access to this field via field- level security. The field will be hidden from all profiles if you do not add it to field-level security.
16. Click on Next.
We will be presented with the Step 5. Add to page layouts page.
17. Select the page layouts that should include this field. The field will be added as the last field in the first two column section of these page layouts. The field will not appear on any pages if you do not select a layout.
18. Finally, click on Save.
How it works…
The Opportunity record formula field Close Date Year Month is automatically derived showing the year and the month name and appears on both the opportunity detail and edit pages.
You can see what this looks like when the Close Date for an opportunity record is 12/31/2020, resulting in the automatic year and month of 2020 December, as shown in the following screenshot:
To summarize, we learned about automating tasks like how to derive year and month values from an Opportunity close date using a formula in the Salesforce CRM.
If you enjoyed this post, check out the book Salesforce CRM Admin Cookbook – Second Edition to discover hidden features and hacks that extend standard configuration to provide enhanced functionality and customization in Salesforce CRM.