Apex Utilities

The following  code controls let the component display based on user interface context.

<apex:outputText value="This is Salesforce Classic exp." 
   rendered="{! $User.UIThemeDisplayed == 'Theme3' }"/> 

In javascript, the same behaviour can be achieved using following 2 lines

function isLightningExp() {
 return( "{! $User.UIThemeDisplayed }" == "Theme4d");

Use SOQL in javascript


<script src="/soap/ajax/36.0/connection.js" type="text/javascript"></script>
<script type="text/javascript">

 // Query for the preference value
 sforce.connection.sessionId = '{! $Api.Session_ID }';
 var uiPrefQuery = "SELECT Id, UserPreferencesLightningExperiencePreferred " +
 "FROM User WHERE Id = '{! $User.Id }'";
 var userThemePreferenceResult = sforce.connection.query(uiPrefQuery);
 // Display the returned result on the page
 document.addEventListener('DOMContentLoaded', function(event){
 document.getElementById('userThemePreferenceResult').innerHTML = 

<h1>userThemePreferenceResult (JSON)</h1>

<pre><span id="userThemePreferenceResult"/></pre>


Leave a Reply