Salesforce Flow and Validation Rules are essential tools that every Salesforce admin frequently uses. In certain scenarios, you may need to create Flows or Validation Rules specifically for the Salesforce mobile app or exclude them from it. Additionally, you might want to implement different logic depending on whether the user is on the mobile app or desktop.

To achieve this, you can configure a flow that behaves differently based on the user’s device. However, keep in mind that this approach only works in screen flows, as it involves a local action, and local actions are supported only within screen flows. It’s also important to note that this method cannot be applied to Validation Rules, as actions are not compatible with them.

Using the User Global Variable to Detect Mobile App Usage

Global variables in Salesforce provide general information about the current user and your organization. One particularly useful global variable, $User, stores data like the user’s ID, email, Profile ID, and more. A lesser-known but valuable property, $User.UIThemeDisplayed, identifies the Salesforce interface the user sees. This variable enables you to design Flows and Validation Rules specifically for the Salesforce mobile app or desktop experience.

The $User.UIThemeDisplayed variable can be used to detect the CSS theme applied to Salesforce web pages for a user. Below are the possible values:

  • Theme1: Obsolete Salesforce theme
  • Theme2: Salesforce Classic (2005) theme
  • Theme3: Salesforce Classic (2010) theme
  • Theme4d: Lightning Experience theme
  • Theme4t: Salesforce mobile app theme
  • Theme4u: Lightning Console theme
  • PortalDefault: Salesforce Customer Portal theme (for portals, not Experience Builder sites)
  • Webstore: AppExchange theme

To detect if a user is on the Salesforce mobile app, check if $User.UIThemeDisplayed equals 'Theme4t'. This allows you to apply different logic depending on the theme being used, such as differentiating between Salesforce Classic and Lightning Experience.

Examples

  1. Validation Rule for Salesforce Mobile App
    Here’s 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:scssCopy codeISPICKVAL(Status, 'Closed') && ISCHANGED(Status) && ISPICKVAL(Reason, '') && $User.UIThemeDisplayed='Theme4t'
  2. Decision Element in Flow
    In this example, a Decision element checks the current user’s theme. Based on the theme detected, the flow takes a different path if the user is on the mobile app.

By leveraging the $User.UIThemeDisplayed global variable, you can customize the behavior of your flows and validation rules, ensuring a tailored user experience on the Salesforce mobile app or desktop.

Related Posts
Salesforce OEM AppExchange
Salesforce OEM AppExchange

Expanding its reach beyond CRM, Salesforce.com has launched a new service called AppExchange OEM Edition, aimed at non-CRM service providers. Read more

The Salesforce Story
The Salesforce Story

In Marc Benioff's own words How did salesforce.com grow from a start up in a rented apartment into the world's Read more

Salesforce Jigsaw
Salesforce Jigsaw

Salesforce.com, a prominent figure in cloud computing, has finalized a deal to acquire Jigsaw, a wiki-style business contact database, for Read more

Health Cloud Brings Healthcare Transformation
Health Cloud Brings Healthcare Transformation

Following swiftly after last week's successful launch of Financial Services Cloud, Salesforce has announced the second installment in its series Read more