Legacy Dev Forum Posts

 View Only

Sign Up

How to use Javascript SDK with Salesforce lightning component?

  • 1.  How to use Javascript SDK with Salesforce lightning component?

    Posted 06-05-2025 18:03

    Eric | 2022-05-26 22:50:24 UTC | #1

    I'm currently working on a project where I need to access the Genesys Cloud API from Salesforce. The company is using Service Cloud Voice rather than the embedded Genesys client, so I was planning to use the Javascript SDK from a lightning component.

    I've downloaded the current SDK js and put it into Salesforce as a static resource (which is how SF requires you to use external libraries), however it doesn't seem to be available to the component even though I can see that the resource is loaded in the network trace.

    Here's how I include it in my component: ` <ltng:require scripts="{!$Resource.GenesysPureCloudJavascriptSDK}" afterScriptsLoaded="{!c.afterScriptsLoaded}" />`

    The "afterScriptsLoaded" function does not get called.

    Has anyone done this successfully? My other approach is to just use the basic API, which I would expect to work, but would be nice to use the SDK for authorization and standards.

    Any clues appreciated!


    Eric | 2022-05-27 00:19:35 UTC | #2

    I think I've figured it out -- adding notes here for anyone else who stumbles across this.

    I had to change` require=function().... to window.require=function()` and now I can access the "require" function from my controller.

    The documentation I found to support this was here: https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/security_share_code.htm

    The most important line of the code to note is: ` window._counter = (function() { ` You must attach _counter to the window object as a requirement of JavaScript strict mode, which is implicitly enabled in Lightning Locker.

    Hope that helps!


    John_Carnell | 2022-05-31 19:19:37 UTC | #3

    He Eric,

    Thanks for the followup. I am sure someone else will run into the same problem at some point or another.

    Thanks, John Carnell Manager, Developer Engagement


    system | 2022-07-01 19:20:11 UTC | #4

    This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.


    This post was migrated from the old Developer Forum.

    ref: 14901