Salesforce Cookies #15

      No Comments on Salesforce Cookies #15

How to use Salesforce REST API in Lightning Component

If you are working with REST/SOAP APIs in the apex class which is being used in the lightning component, then using UserInfo.getSessionId() will give the session id which can not be used to make the API calls due to security restrictions.

There is a workaround for this problem which uses Visualforce page and we can extract the session id from the VF page.

Using Session Id in AuraEnabled method which works with REST API

<apex:page contentType="application/json">
// In apex class you can get the session Id as written below
public static String getSessionId() {
     return Page.SessionId.getContent().toString();

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.