1

I have written code in apex class ,I want to check the url belongs to classic or Lightining

string UrlDomainName  = URL.getSalesforceBaseUrl().getHost();
             if(classicView)
            {
               // classic code
            }
            else
            {
                // lightining code
            }

what i have to write instead of classic view for finding classic url,please anyone help me to rectify this issue

4

URL checking is not ideal way of detecting user's current mode. There is a better way.

UserInfo.getUiThemeDisplayed();

This method returns a string from the following list.

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

Webstore—Salesforce AppExchange theme

Theme3 should be classic and Theme4d is for LEX. More details here.

if(UserInfo.getUiThemeDisplayed() == 'Theme3')
{
//classic code
}
else if(UserInfo.getUiThemeDisplayed() == 'Theme4d')
{
// LEX code
}
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.