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 ....