Get Session Id using Apex in Salesforce

String sessionId = UserInfo.getOrganizationId()+''+UserInfo.getSessionId().SubString(15);

  • Anil

    What is $API.SessionId and $API.SERVER_URL_270 and how to access them in apex

    is $API.SessionId = orgId + user session Id ?

    • $Api.Session_ID is to get session id in VF page

      • Anil

        There is no direct method to get the same in apex class? And also the API.ServerUrl.

        These i can directly access in vf, but in apex i need to build or structure it .

        • UserInfo.getSessionId() – it will work in apex but you cannot get the session id in debug log using it.