I have an URL that was saved in a Text(255) field of the Custom Metadata Type. I wanted to refer this Url on to the Lightning component, to make my custom onClick() to redirect to this Url. How can I pass this URL to window.location.href?

Do I need to query the field in an Apex Controller class using:

Select Id, UrlField from MyPortal_Configuration_Setting__mdt

If yes, how can implement in Component's JS controller? If no, what is the valid workaround for referring URL from Custom Metadata type? Can someone take a look at this please?

1 Answer 1


To redirect to an url, if you're in Lightning Experience you should make use of the force:navigateToURL event.

To get the Custom Metadata Type, I'm afraid you'll have to query the server via an Apex Controller, yes. I tried to use Lightning Data Service, but unfortunately it doesn't work with Custom Metadata. But I would definitely keep an eye on it as it would make sense to support Custom Metadata Types in LDS in the future.

  • I was able to query this way: @AuraEnabled public static My_Portal_Configuration_Setting__mdt getLogoutUrl() { List<My_Portal_Configuration_Setting__mdt> logoutUrl = [Select Id, Logout_URL__c from My_Portal_Configuration_Setting__mdt LIMIT 1]; return logoutUrl[0]; }. On JS I tried to implement this: But received undefined: var logUrl = component.get("c.getLogoutUrl"); console.log('Url: ' +logUrl); Could you please help me out in implementing in JS?
    – SatyaV
    Commented May 18, 2017 at 12:20
  • Have you tried returning just a String ? Commented May 18, 2017 at 12:23
  • Actually I was getting this in console Url: [object Object].
    – SatyaV
    Commented May 18, 2017 at 12:27
  • Can you use console.log('Url: ', logUrl); ? "," instead of "+", and see what's inside the object. Commented May 18, 2017 at 12:31
  • 1
    Let us continue this discussion in chat. Commented May 18, 2017 at 13:08

You must log in to answer this question.

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