function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
bretondevbretondev 

How to get Organization ID from Lightning Component?

Hello

Is it possible to get current org Id from Lightning Component controller?

I have tried that but i get undefined value :
var orgId = $A.get("$Organization.Id");
Best Answer chosen by bretondev
Ravi Dutt SharmaRavi Dutt Sharma
Hi,

I guess $Organization global variable only works in Visualforce and not in lightning. In lightning, you need to create an apex controller and fetch the org id in the controller.
 
String orgId = UserInfo.getOrganizationId();

 

All Answers

Ravi Dutt SharmaRavi Dutt Sharma
Hi,

I guess $Organization global variable only works in Visualforce and not in lightning. In lightning, you need to create an apex controller and fetch the org id in the controller.
 
String orgId = UserInfo.getOrganizationId();

 
This was selected as the best answer
bretondevbretondev
Ok, that is what I thought too.
it's a pity that I have to create Apex controller just for this need
Ajay K DubediAjay K Dubedi
Hi Bretondev,

Get Salesforce organization id using apex:
Id OrgId = UserInfo.getOrganizationId();
Please mark as best answer if it helps you.

Thank You
Ajay Dubedi