3

Inside a formula field I want to be able to determine whether the org is the production org or a full copy sandbox. After researching I came up with this:

IF($Organization.Id = 'XXXXXXXXXXX', "PROD", "FULL SANDBOX")

However it appears that a full copy sandbox takes the id from the production org as well.

Originally I wanted to use $Organization.IsSandbox but that field is not accessible within the formula fields.

  • As far as I know, there's still no reliable way to know what type of sandbox you're in. You can only figure out if you are, or are not, in a sandbox, and even then, not in all types of formulas. – sfdcfox Nov 30 '17 at 8:11
4

When I asked how to Differentiate Production/Sandbox Instance? I ended up following a strategy of parsing the username. Somewhat brittle, perhaps, but it should work for the majority of your users. If you add this field detection at the user level, then you will be able to merge $User.Is_Production__c into just about any formula in the system.

You could certainly adapt this solution to your needs with a formula that renders everything after @mycompany.com. as the approximate sandbox name.

RIGHT(Username, LEN(Username) - LEN("@mycompany.com") - FIND("@mycompany.com.", Username))

Then you can reference $User.Sandbox_Name__c = "MyFullSandbox" in your formulas, for example. You could probably make this solution more robust by blending the approach with SandboxPostCopy and Hierarchy Custom Settings, taking the most common value amongst all users and storing that as the org default.

2

I am thinking about a complecated way of how can you detect a sandbox.

  • Create hierarchy custom setting with field isSandbox
  • Create class that implements SandboxPostCopy Interface. This class populates hierarchy custom setting on company level isSandbox as true
  • on each sandbox refreshing or creation process you need to specify "Apex Class" from previous point at last step.

After that it is possible to reference hierarchy custom setting in field formulas in the following way: $Setup.CustomSettingName__c.CustomFieldName__c

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.