custom links that work in both classic and lex

if you want a single custom link that works in classic or lightning, you need to create the links in a very simple visualforce page and embed the page in the page layout, which will show in classic and lex and looks pretty fine. you can make it look better if you really want.

note : you must set target = blank or target = top for the lightning portion of the link. if you do not specify target, or use self or parent, then opening the link in a new window will open the home page in lex.

if you try to use IF logic to evaluate UITheme on a custom link, it almost works, but it only works if you open in the same window. if you open in a new window, it will always evaluate to classic, and the known issue for this is marked as ‘no fix’. because of course…and you cannot prevent users from opening in new window.

the suggested workaround on the KI is to use a formula field. a formula field is not in any way a custom link, so this is not really an answer in my book.

note that if this is on a custom object you can use dynamic forms in lex which will remove the custom links section entirely (a feature, apparently), then you can add a visualforce page to the record page in lightning only. So classic users will see the normal custom links section on the page layout, and lightning users will see the vf page - wherever you add it to the record page. no if logic etc required. you may still need to set target on the links, have not tested.

note 2 - yes you could just create separate links for classic and lightning, show them both on the page layout, and leave it to users to choose wisely. if salesforce was not a gazillion dollar company that charges gazillion dollar market leader magic quadrant prices that would be pretty ok. but my efforts to position salesforce as a high quality product benefits from not having duct tape visible all over the place. whats under the hood stays under the hood, but you gotta keep it outta sight!

so here is the page we are using on campaigns.

<apex:page standardController="Campaign" sidebar="false">
<head>
<apex:slds />
</head>
<body class="slds-scope">
    <p>                  
     <apex:outputlink value="{!URLFOR(
         IF($User.UIThemeDisplayed = 'Theme3',
           ('/00O40000002ORGS?pv0='+LEFT(Campaign.Id,15)),
           ('/lightning/r/Report/00O40000002ORGS/view?fv0='+LEFT(Campaign.Id,15))))}" target="_top">View All Campaign Members
     </apex:outputlink>
    </p>
    <p>
     <apex:outputlink value="{!URLFOR(
        IF($User.UIThemeDisplayed = 'Theme3',
          ('/00O400000033Kf0?pv0='+LEFT(Campaign.Id,15)+'&pv1='+$User.FirstName+' '+$User.LastName),
          ('/lightning/r/Report/00O400000033Kf0/view?fv0='+LEFT(Campaign.Id,15)+'&fv1='+$User.FirstName+' '+$User.LastName)))}" target="_top">View MY campaign members
      </apex:outputlink>
    </p>
    <p>
     <apex:outputlink value="{!URLFOR(
        IF($User.UIThemeDisplayed = 'Theme3',
          ('/00O40000003a6EM?pv0='+LEFT(Campaign.Id,15)),
          ('/lightning/r/Report/00O40000003a6EM/view?fv0='+LEFT(Campaign.Id,15))))}" target="_top">View Related Opportunities
      </apex:outputlink>
    </p>
</body>
</apex:page>

and here is a screenshot in classic and lex. you can get fancy if you want and go 3 columns…i’ve already spent much too much time on this!

campaign.png

 
0
Kudos
 
0
Kudos

Now read this

Deploying a Permission set for a Managed Package from Sandbox

WE have rolled out FinancialForce HCM, fka Vana HCM. In an rather conventional move, we did our development in a sandbox, and deployed our changes to production. Most of the deployment was regular run-of-the-mill workflows, a few custom... Continue →