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


No comments:

Post a Comment

Sharing is Caring!!! Share this with your friends!!!

submit to reddit