4

There's been a few questions around working out if an org is a sandbox or not, but typically these are done via Apex. I need to find out an org's type (only sandbox/prod - dev etc. don't matter) using just the instance URL in Javascript from a Node application.

Current Solution

Worst case scenario I use a REST API call to query the org type and determine the state of play, but the best I've come up with from Javascript right now is to use regex:

var pattern = new RegExp(".*cs[0-9]{1,2}(\.my)?\.salesforce.com");
return pattern.test(instance);

This will return true for URLs such as "https://cs22.salesforce.com", "https://lacey.cs22.my.salesforce.com" and false for things like "https://na1.salesforce.com".

Question

Am I missing anything obvious here? Is there some format of Sandbox url I'm not catering for?

It doesn't need to work for every conceivable string thrown at it, it's working on the instanceUrl returned by Salesforce along with the access tokens etc. during the OAuth flow. What I need is something that's good enough for 99% of the orgs out there right now.

3

Not sure if you need it all, but the following additional subdomains come to my mind, which might not be covered by your current regex:

  • visualforce domain urls
  • namespaced managed packages
  • lightning urls
  • salesforce one app
  • Yeah, I thought of these but I don't think they ever play a part in login thankfully! – Matt Lacey Feb 20 '15 at 1:06
3

Based on the Salesforce PM response here, you can safely determine based on the instance url. Issue will be if you are using a custom my domain, then you will have to write a Rest API to expose the status.

  • Yeah I think for login the my custom ones aren't too much of an issue... – Matt Lacey Feb 20 '15 at 1:08

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.