Search code examples
salesforcehere-apisalesforce-lightning

Error while loading library mapsjs-core and mapsjs-service in salesforce lightning


I am trying to load Here maps library in lightning component but on load page is throwing below error.

[Cannot read property 'Object' of undefined] eval()@https://wellmanage--onbdev.lightning.force.com/resource/GRG_Leaflet/GRG_Leaflet/Here-mapsjs-core.js:6:1666 Proxy.eval()@https://wellmanage--onbdev.lightning.force.com/resource/GRG_Leaflet/GRG_Leaflet/Here-mapsjs-core.js:320:26


Solution

  • According to the stack trace and error, it looks like the HERE scripts are loaded in an environment which doesn't have access to the JavaScript window object, and therefore cannot be evaluated properly.

    I'm not familiar with Salesforce Lightning, but it should be possible to execute JavaScript code as their documentation states:

    A component bundle can contain JavaScript code in a client-side controller, helper, or renderer. Client-side controllers are the most commonly used of these JavaScript resources.

    However, it seems there is a peculiar way to load external scripts, which is described on this page. In particular:

    The framework’s content security policy mandates that external JavaScript libraries must be uploaded to Salesforce static resources. For more information on static resources, see “Static Resources” in the Salesforce online help.