How to get Salesforce Organization Id using Apex?

How to get Salesforce Organization Id using Apex?

UserInfo.getOrganizationId() can be used to fetch the Salesforce organization id using Apex.

Sample Code:

Id OrgId = UserInfo.getOrganizationId();
System.debug(
    'Org Id is ' +
    OrgId
);

UserInfo.getOrganizationId() allows us to programmatically get our Salesforce Organization Id.

Leave a Reply