2

I am trying to generate a report in Lightning with the help of custom link on the Contract. Thought of using the url hack like classic by adding the parameters but no luck in generating the report with the help of custom link through this approach. I tried to use the same custom link to generate reports in LEX as well as classic depending on the user.

Below are the options tried for genrating the report:

Option-1: Provided Full url to the custom link

https://org62--mydev.lightning.force.com/one/one.app#/sObject/00O30000002NnM7/view?fv4= {!Contract.ContractNumber}

This is working fine but needs to give Full URL and If i move to another sandbox this is failing and requires a change in every environment.

Also tried giving only this in the custom link - /one/one.app#/sObject/00O30000002NnM7/view?fv4= {!Contract.ContractNumber} --> WORKING ALL TIMES

/00O30000002NnM7?pv4={!Contract.ContractNumber} --> WORKING IN CLASSIC but in LEX it's not displaying the report

Option-2: I used a condition to differentiate between classic and LEX user using the Theme and tried to use the URL but no luck.

IF($User.UIThemeDisplayed=='Theme4d',

'/one/one.app#/sObject/00O30000002NnM7/view?fv4=',

'/00O30000002NnM7?&pv4=')

{!Contract.ContractNumber}

)

When I do this I am getting an error as below: Illegal URL assignment

Can anyone help me on the Option-2 as I can differentiate between classic and LEX user and direct to the correct URL?

2
  • what you are doing is highly discouraged and unsupported. may i inquire as to why you are doing this? – glls Dec 20 '17 at 5:23
  • @glls I am doing this to generate a report when you click on the link in classic or LEX and depending on the user theme i want this to go to the correct URL. Can you suggest me proper approach if this not the right way to do it? – sri Dec 20 '17 at 21:22
2

You need to create a lightning controller with the component and use the force:navigateToURL event: https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/ref_force_navigateToURL.htm

Say you have a component that has a link:

<a href="<some url>">My Report</a>

Drop the href and pass and onclick handler to it

<a href="" onclick="{!c.goToReport}">My Report</a>

Now handle the event in the controller and call the navigate to url event

goToReport: function(component, event, helper) {
    var urlEvent = $A.get("e.force:navigateToURL");
    urlEvent.setParams({
      "url": "<report url path with query params>"
    });
    urlEvent.fire();
}
1
  • Thanks for your inputs on this. As this is a custom link with URL i think we can directly give the URL that needs to be routed. And I am trying to differentiate between classic user and Lightning user depending on the Theme4d and route them to the appropriate URL but it is not allowing me to do that. Can you suggest me some approach on Option-2? – sri Dec 20 '17 at 20:10
1

To address the issue of the base URL changing in each environment, I have a Hierarchy Custom Setting called Environment_Settings__c with a few variables that are commonly used (such as Base_URL__c) and the default values are specific to the environment.

Hierarchy Custom Settings are accessible from field formulas, email templates and many other places in Salesforce.

If you need to retrieve the custom settings in Apex, you can use:

Environment_Settings__c envSettings = Environment_Settings__c.getInstance();
String classicBaseURL = envSettings.Base_URL__c;
String lexBaseURL = envSettings.LEX_Base_URL__c;

This let's you deploy your code, fields, etc and they work correctly without making code changes per environment.

You just need to remember to update Environment Settings after you do a Sandbox refresh!

Hope this helps.

Mike

3
  • Can you suggest me what can i do with Option-2 as I want to direct the URL depending on the theme displayed whenever the custom link is clicked.? Can this be done using the Option-2 approach? – sri Dec 20 '17 at 21:23
  • Yes, I would use $User.UIThemeDisplayed variable to determine if user is in Classic or LEX and then build a string based on the environment. – Mike Paisner Dec 22 '17 at 16:11
  • Additional note, I have found that UIThemeDisplayed may give the incorrect result if you have multiple tabs open in your browser where some tabs are classic and some are LEX. This happens in both Chrome and Firefox. This is a bigger problem for developers and testers that are switching between classic and LEX more frequently. This is less of a problem for users who don't switch back and forth between Classic and LEX as much. I haven't found a better alternative. – Mike Paisner Dec 22 '17 at 16:22

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.