So what can we do exactly with Groovy? Here are some Groovy one-liners that show what you can do with the shortest code snippets possible.
Formula fields calculations
Formula fields are fields that do not show data that was entered by a user or is stored in the application. These are fields that show a calculated value. Calculated the moment the field was generated to be shown on a screen, calculated possibly differently for every user, in the users context, depending off course on how sophisticated the formula is.
The example below will calculate in real-time a weighted opportunity revenue by multiplying the opportunity revenue with the opportunity win probability:
Here an example a colleague of mine shared (who goes by the stage name of the Wise Old Wizard Of Woking aka WOWOW) whereby the parent account name for an account is displayed:
The following is an example of a formula field that shows a text value: the concatenation of the contact title, the contact first name and last name:
A result of the formula above can be seen here.
Remember that you do not need to memorize any of the field names or function names when coding in Groovy. They can be all be inserted in your code using the function palette.
Conditionally required/updatable fields
When create new fields in App Composer, you can specify using a checkbox whether or not a field is required or updatable. But sometimes that is not enough. Using groovy you can add conditions on when a field should be required or updatable.
The example below will make an opportunity field required if the revenue value is above 1,000,000:
In Sales Cloud, it is possible to include screens or parts of screens from other applications. This is called an application mashup. These can be other applications existing in the internal IT landscape or external websites that manage valuable information for your users. Another good example is how you can enrich an Sales Cloud by blending reports and dashboards into the user experience.
In order to add a news website for on the account page, a subtab of type ‘Web Content’ needs to be added.
Sales Cloud will only allow ‘https’ secured mashups and not all websites (LinkedIn, Twitter, …) will you allow to embed their content in another application.
Dynamic layout filters
Dynamic layouts in Application Composer is the ability in Sales Cloud to use different layouts when presenting data to users. The right layout for each of the users is chosen based on a qualification:
- The default layout is used when no other layouts qualify. From top to bottom, the first layout that qualifies will be the one the user sees.
- Layouts can be chosen based on their record types: e.g. an ‘Prospect’ account can be shown in a different layout than when the account would be a ‘Customer’
- Layouts can be used based on the user role: e.g. an opportunity seen by a salesrep might not be shown in the same layout than when his sales manager would look at the same opportunity in Sales Cloud.
- Layouts can be used based on an advanced Groovy expression
- Any combination of the last 3
The example below will show opportunities always using the ‘Default Layout’ except for won opportunities where the ‘Competitor Layout’ is used for any user and any opportunity type, so that the salesrep can specify some competitor related information interesting to win other opportunities.
Object workflow conditions
Another nice example of a groovy one-liner is the condition that you can set when defining object workflows.
The example below shows the definition of an object workflow that will create a review task for a sales manager each time one of his salesreps creates an open opportunity with an open opportunity revenue value above 10,000,000. The only bit of Groovy needed here was the object workflow condition to make sure the task would not be created for all newly created opportunities.
Which should be implemented as follows: