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

How can i know the environment(sandbox or Production)?

We can know the environment by looking at the URL. Sandbox orgs basically contains "CS" as the first two letters something as whereas production org's can have NA/EU/AP etc..,

If you want to determine this programatically through APEX, you may use the getHost() method on the System URL class.  

Sample Code :

System.debug('Host: ' + URL.getSalesforceBaseUrl().getHost());

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

Thank You....
Hi Syam,

By querying from Organization object as well,we can determine whether its sandbox or production if u want to determine using code.
See the example here