1

We are migrating a section of the company to Lightning. We have some objects whose records open in custom Visualforce pages because we wanted to display information across multiple tabs. We achieved this by overriding the Standard View button to redirect to custom Visualforce page.

Now, the problem is that for our SF Classic users this button (URL) should still redirect to the old custom VF page, but our Lightning users need to be redirected to the standard record page (i.e. - default button behavior). Is there any way to achieve this?

enter image description here

1
  • You can try using nooverride=1 parameter to avoid navigation in lightning. URL: I use /one/one.app#/sObject/{recordId}/edit?nooverride=1
    – Raul
    Commented Oct 18, 2017 at 11:42

2 Answers 2

4

You could redirect with action attribute of apex:page tag based on contextfrom $User.UITheme and add nooverride=1 parameter when page is running in Lightning:

Here is an example, tested it, seems to be working. Would be awesome to generate the URL dynamically instead of hardcoding.

<apex:page standardController="Contact" 
    action="{!(IF($User.UITheme == 'Theme3', 
        null, 
        URLFOR('/one/one.app#/sObject/' +Contact.Id+ '/view?nooverride=1')
        ))}">
    <!-- your page code continues -->
</apex:page> 
2

You need to use UserInfo.UIThemeDisplayed() to identify if your user is in classic view or in Lightning Experience.

On your page's action attribute call a controller method and in the method check if current user is in Lightning then redirect them to standard page else they will be redirect back to custom VF page.

public pagereference prrediect() {
    if(UserInfo.getUiThemeDisplayed() == 'Theme4d')
        return new pagereference('/one/one.app#/sObject/'+recordId+'?nooverride=1'); //you can change this URL

   return null;
}

Introducing UI Theme Detection for Lightning Experience

2
  • 1
    Thank you for your answers. I gave you both an upvote, but I decided to accept @RahulSharma answer since he made the first comment on my post, I hope you won't hold it against me. I also used his approach, but this approach works as well, I tested it.
    – smukov
    Commented Oct 18, 2017 at 12:21
  • @smukov no issue mate. But I don't understand WHY someone down voted this answer. Commented Oct 18, 2017 at 12:24

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .