Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

The inspiration for this question comes from an apparent requirement to hard-code a production org id. Is it safe to rely on the production org id always remaining the same?

Reason for hard-coding is because this is in a mobile app rather than part of the Salesforce environment.

Context: we want our app to be able to download documents successfully when logged in to Sandbox as well as Production. In order to determine the correct URL to build to use servlet.shepherd, we need the mobile app to be able to determine whether it is logged into production or not, and if it's logged into a sandbox, ideally specifically which sandbox. We are using the iOS Mobile SDK version 4.0

EDIT: for the avoidance of doubt my question is not "how else can I solve my problem", my question is exactly as specified in the title. I'm looking more to discover whether hard coding production id in a mobile app is safe, than alternatives to doing so.

share|improve this question

It shouldn't change, but why hardcode?

I would put the OrgId in a custom setting, and read it from there. That way you can test in Sandboxes, work in Prod and, if it ever changes, it's 5 minutes to modify without any code "movement".


There are a few things you can do that do not involve hardcoding... hopefully one of them will work

  1. To log into production you hit, sandbox is Perhaps you can identify your environment because of that.
  2. Alternatively, you can call a method in SFDC to return whether the org you're hitting is "Prod" or Sandbox". A simple SoQL query will return that: select Id, IsSandbox from Organization limit 1. See here for more details.
share|improve this answer
Thanks, I've edited my question to include the reason for hard-coding – Brad Thomas Mar 3 at 16:21
Good Edit.... can you give us more context? I have a few ideas, but not sure which one(s) apply... – Sebastian Kessel Mar 3 at 16:22
OK I have added more context to the question, thanks – Brad Thomas Mar 3 at 17:01
@SebastianKessel When you log in through the REST API, salesforce gives you this information. There's no need to do a query to figure out this data. – sfdcfox Mar 3 at 17:15
Brad, I don't know that they can change. But I also don't know that they can't. I don't think Salesforce guarantees that an ID will stay immutable. The good thing, though, if that if SFDC is planning to change the format of IDs you will have enough notice to change your code accordingly. I think you can leave your code as is. – Sebastian Kessel Mar 3 at 17:34

A Sandbox's ID may change during a refresh, and definitely if you create a new Sandbox. Production ID values will always remain the same. However, when you log in, your session information already includes the org ID, and is available when you log in. You'll get an Identity ID URL through most authentication schemes, that might look like this:

(Example URL copied from the Salesforce REST API docs).

You can call this URL with your new Access token to get information about the org and user you're logged in as.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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