When I’m within a Salesforce org, how can I tell if that org is a Scratch Org or not?
Ideally this would be via Apex, but it could be an API call if required.
This would be useful information for the creator of a managed package who may not otherwise know what type of org is running the code.
I’ve had a couple of thoughts on how this might be achieved:
- Check if the pod/instance that Scratch orgs are created on are separate from the general population of sandbox orgs. I suspect that scratch orgs have dedicated hardware. E.g. a new scratch org I just created is on p0/CS31.
- Look for describe Metadata that is unique to only scratch orgs.
The SourceMember sObject is only present in scratch orgs. Its presence would be a sign that you are in a scratch org. The gotcha would be that it is only accessible via the Tooling API and not Apex alone.