salesforcesimple-salesforce

Detect type of Sandbox (Salesforce)


Salesforce supports different sandboxes.

For example "partial" or "development" sandbox.

Is there a way to detect which kind of sandbox my script is connected to?

I use Python and simple_salesforce.


Solution

  • My Python's not good enough. I can give hints but you'll have to experiment a bit yourself.

    https://github.com/simple-salesforce/simple-salesforce "Additional features" says there's internal class that can expose to you session_id and instance.

    You can use these to craft a HTTP GET call to

    Authorization: Bearer {session_id}
    {instance}/services/data/v51.0/limits
    

    The "limits" resource will tell you (among others) what's the data and file storage available in this org. It'll return a JSON similar to

    {
        ...
        "DataStorageMB" : {
            "Max" : 200,
            "Remaining" : 196
        },
        ...
    }
    

    Use DataStorageMB.Max and table at bottom of https://help.salesforce.com/articleView?id=sf.data_sandbox_environments.htm&type=5 to figure out where you are. 200 => Developer, 1024 => Developer Pro...


    Edit - if you'd be using Apex (maybe exposed as REST service, "simple salesforce" has nice built-in to access them)

    Integer storageLimit = OrgLimits.getMap().get('DataStorageMB').getLimit();
    System.debug(storageLimit);
    String sandboxType;
    switch on storageLimit{
        when 200 {
            sandboxType = 'Developer';
        }
        when 1024 {
            sandboxType = 'Developer Pro';
        }
        when 5120 {
            sandboxType = 'Partial Copy';
        }
        when else {
            sandboxType = 'Full Copy';
        }
    }
    System.debug(sandboxType);