4

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.

2 Answers 2

4

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".

UPDATE

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 login.salesforce.com, sandbox is test.salesforce.com. 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.
8
  • Thanks, I've edited my question to include the reason for hard-coding Commented Mar 3, 2016 at 16:21
  • Good Edit.... can you give us more context? I have a few ideas, but not sure which one(s) apply... Commented Mar 3, 2016 at 16:22
  • OK I have added more context to the question, thanks Commented Mar 3, 2016 at 17:01
  • 1
    @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
    Commented Mar 3, 2016 at 17:15
  • 1
    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. Commented Mar 3, 2016 at 17:34
4

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:

https://login.salesforce.com/id/00Dx0000000BV7z/005x00000012Q9P

(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.

2
  • Just for clarity -- if SFDC moves your Prod org to a new POD, will the orgId change?
    – cropredy
    Commented Apr 15, 2017 at 2:52
  • @cropredy Production will not change, even if your org migrates pods. Many older orgs actually have an org Id that do not match their pod identifier.
    – sfdcfox
    Commented Apr 15, 2017 at 2:55

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .