How to find whether we logged in from Sanbox in Salesforce?

URL.getSalesforceBaseUrl().getHost()) will give the URL of Salesforce instance.

Sample Code:

public Boolean isSandbox() {
    return URL.getSalesforceBaseUrl().getHost().left(2).equalsignorecase('cs');
}

Another way to find is

SELECT Id, IsSandbox, InstanceName, Name FROM Organization limit 1

Cheers!!!

No comments:

Post a Comment