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.

  • Is that lightning component? – Pranay Jaiswal Dec 6 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 Dec 6 at 15:10
  • How is this post any different than your previous question? – Adrian Larson Dec 6 at 15:11

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

  • 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 Dec 6 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 – Pranay Jaiswal Dec 6 at 15:23
  • Thanks a lot Pranay – medhavi Dec 7 at 14:06

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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