Newer Version Available

This content describes an older version of this product. View Latest

getRESTAPISessionKey()

Returns the Salesforce REST API session key.

Use this method when your embedded app needs to interact with the Salesforce REST API, such as executing a SOQL query.

Don’t use the session key to manage custom objects or fields. You can use the session key to create and update object records. Apps that use lightning:container should work with data, not metadata.

It's important to keep your API key secure. Don't give this key to code you don't trust, and don't include it in URLs or hyperlinks, even to another page in your app.

Salesforce uses the no-referrer policy to protect against leaking your app's URL to outside servers, such as image hosts. However, this policy doesn't protect some browsers, meaning your app's URLs could be included in outside requests.

Important

Sample

Used within a JavaScript app uploaded as a static resource and referenced by lightning:container, this example gets the REST API session key and uses it to execute a SOQL query.
1componentDidMount() {
2  let sid = LCC.getRESTAPISessionKey();
3  let conn = new JSForce.Connection({accessToken: sid});
4  conn.query("SELECT Id, Name from Account LIMIT 50", this.handleAccountQueryResponse);
5}

You can view and download this example in the Developerforce Github Repository.

Arguments

None.

Response

Name Type Description
key string The REST API session key.