0

I am storing the public url of a pdf file in a field of a custom object. I am able to successfully retrieve the url. how can I fire the url when a user click a button? Is it possible through JS controller? Thanks in advance for your help.

3
  • Is that lightning component? Commented Dec 6, 2018 at 15:07
  • yes. I tried doing it in href tag <a href="{!Module.URL__c}" target="_blank">DOWNLOAD </a> but this does not work. Module is the nale of the custom object and URL__C is the field name.
    – medhavi
    Commented Dec 6, 2018 at 15:10
  • How is this post any different than your previous question?
    – Adrian Larson
    Commented Dec 6, 2018 at 15:11

1 Answer 1

0

You can do that using e.force:navigateToURL,

on press of a button fire the below event, it will open that URL

gotoURL : function (component, event, helper) {
    var urlEvent = $A.get("e.force:navigateToURL");
    urlEvent.setParams({
      "url": 'fileURL';
    });
    urlEvent.fire();
}

src: https://developer.salesforce.com/docs/component-library/bundle/force:navigateToURL/documentation

2
  • Thanks for the reply Pranay. It is wrking when I am assigning a static url but how do I pass the url dynamically in this function? My url is stored in URL__c field of a custom object which I am retrieving in the APEX class. Thanks a lot in advance.
    – medhavi
    Commented Dec 6, 2018 at 15:22
  • Follow this, this will tell u how to get that URL from APex, developer.salesforce.com/docs/atlas.en-us.lightning.meta/… Once you got the URL you can redirect Commented Dec 6, 2018 at 15:23

You must log in to answer this question.

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