Creating Flows and Validation Rules Based on Salesforce Mobile App vs Desktop Usage

Creating Flows and Validation Rules Based on Salesforce Mobile App vs Desktop Usage

Salesforce Flow and Validation Rules are essential tools that almost every Salesforce admin uses on a daily basis. In some cases, you may want to create Flows or Validation Rules specifically for (or to exclude) the Salesforce mobile app. Additionally, you might want to apply different logic based on whether the user is on the mobile app or desktop.

You can use this action to build a flow that behaves differently based on the device. However, it's important to note that this action works only in screen flows because it is a local action, and local actions are only supported in screen flows. Moreover, since it is an action, it is not possible to use it in validation rules.

Using the User Global Variable to Detect Mobile App Usage

Global variables provide general information about the current user and your organization. One of the most useful global variables, the $User global variable, stores information about the current user. Most people are familiar with it for retrieving values like the user's ID, email, Profile ID, and more. However, there is another value, $User.UIThemeDisplayed, that can be used to identify the Salesforce look and feel a user sees on a given web page. By leveraging this global variable, you can easily build Flows and Validation Rules specifically for the Salesforce mobile app or desktop.

It is possible to use this variable to identify the CSS used to render Salesforce web pages to a user. Here are the possible values of $User.UIThemeDisplayed.

  • Theme1: Obsolete Salesforce theme
  • Theme2: Salesforce Classic 2005 user interface theme
  • Theme3: Salesforce Classic 2010 user interface theme
  • Theme4d: Modern "Lightning Experience" Salesforce theme
  • Theme4t: Salesforce mobile app theme
  • Theme4u: Lightning Console theme
  • PortalDefault: Salesforce Customer Portal theme that applies to Customer Portals only and not to Experience Builder sites
  • Webstore: AppExchange theme

To detect if a user is on the Salesforce mobile app, you need to check if $User.UIThemeDisplayed equals 'Theme4t'. Additionally, based on the possible values of this variable, you can apply different logic for other themes, such as Salesforce Classic and Lightning Experience.

Examples

1- Here is a validation rule that requires users to enter a case reason when changing the status to Closed, but it only applies to the Salesforce Mobile App.

ISPICKVAL(Status, 'Closed') && 
ISCHANGED(Status) &&
ISPICKVAL(Reason, '') &&
$User.UIThemeDisplayed='Theme4t'
Validation Rule for Salesforce Mobile App

2- Here is a Decision element that checks the current user's theme. Based on the result, the flow takes a different path if the user is on the mobile app.

Check the Mobile App in Decision Element

Be the first to comment

Leave a Reply

Your email address will not be published.


*