All Ideas

Idea Details

Post an Idea
This idea has been delivered and can no longer be voted or commented on. If you’d like to add to this conversation, please post a new idea.
1,170  Points voting closed
Delivered
Idea is generally available.

Determine sandbox name vs production from apex

Developer Tools

I'd like a System method to determine whether you're on production or a sandbox, and if it's a sandbox, what the sandbox name is. This could also be provided as a field on the Organization standard object.

This would be helpful both for allowing SOA callouts to point to test URL's instead of production, as well as allowing us to do some automation for our staging environments (such as giving developers higher levels of access than in production) without worrying that these changes might occur in production.

· Flag

Latest Comment from Salesforce

  • Josh Kaplan - 6 years ago

    I think you are just looking for the getHost() method on the System URL class.  All sandbox pods are cs*, and all production pods are not.

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

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

    Does this solve the need?  
  • Upvotes
  • Downvotes

Ideas

Apps

from AppExchange

Questions

Help us to keep IdeaExchange clean by pointing out overlapping ideas. We'll investigate your suggestion and merge the ideas if it makes sense.



 

 

Thanks for your merge suggestion. We will review it shortly and merge the ideas if applicable.

Salesforce takes abuse situations very seriously. Examples of abuse include but are not limited to posting of offensive language or fraudulent statements. To help us process your request as quickly as possible, please fill out the form below describing the situation. For privacy and security reasons, the final outcome of an abuse case may not be revealed to the person who reported it.


 

Thank you for your feedback. We take abuse seriously and will investigate this issue and take appropriate action.