3

Background

I am using this approach Call REST API from Lightning Components without Named Credentials to call the Salesforce REST API from a Lightning component.

It works when I call this URL:

/services/data/v45.0/tabs

But when I make this call:

    cmp.find('lc_api').restRequest({
        'url': '/services/data/v45.0/appMenu/AppSwitcher',
        'method': 'get',
        'body': null
    }).then($A.getCallback(function (apps) {
        cmp.set('v.apps', apps);
    })).catch($A.getCallback(function (err) {
        console.log(err);
    }));

I get this error:

Error at new Aura.externalLibraries (https://static.lightning.force.com/cs87/auraFW/javascript/0Rz6fp7Oruhim-Qzw_AgRQ/aura_proddebug.js:26554:23) at ...

If i change the code to:

    cmp.find('lc_api').restRequest({
        'url': '/services/data/v45.0/appMenu/AppSwitcher',
        'method': 'get',
        'body': null
    }).then($A.getCallback(function (results) {
        let data = JSON.parse(JSON.stringify(results))
        cmp.set('v.apps', data.appMenuItems);
    })).catch($A.getCallback(function (err) {
        console.log(err);
    }));

It works, because I am converting the response to a String and then back to an Object.

Questions

  1. What is causing it?
  2. Why do I need to so this sometimes and not others?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.