I'm using Salesforce as the identity provider (IdP) in a single sign-on application I'm developing in php. After the user logs into Salesforce.com to authenticate, they are redirected to my app and the app gets a string of attributes from Salesforce, including any custom attributes I configure in the Connected App management panel inside Salesforce. E.g. userId, email, first name, etc.

I want to derive a globally unique user identifier from these attributes so that I can use it as an index into my own database table to store user preferences and manage their billing, that will persist even if the user changes their email address, etc.

From some reading it looks like userId is not globally unique, but perhaps by concatenating it with the Organization ID I can create a unique ID like so:


Is this a good technique or is there a best practice that can be applied here?

Or actually is the userId sufficient since it really links to an individual person no matter what org they log into?


The user Id alone should be sufficient. The only time a user Id is duplicated is when the user is copied into a Sandbox from a Production environment; the Id technically refers to the same user that exists in different orgs. That said, you could decide to go with a user-id/org-id pair, as that is definitely a unique value.

  • Ok thanks for the clarification!
    – Maddix
    Apr 19 at 21:46
  • I just realized I also need the user ID for billing purposes. In that case it seems it would make sense to just use the user ID without the org ID to link to an account on my server. They can use my application under one billing account no matter what org they log into. Does that make sense?
    – Maddix
    Apr 19 at 21:50
  • @Maddix They're either logging in to their own production or a sandbox clone of their production. The same person might have multiple orgs, and those would be separate Id values. You may want to set up a mechanism to keep track of all the orgs to which they're logged in to. Alternatively, if you do org-based billing, storing the Org Id separately might also be a good idea.
    – sfdcfox
    Apr 19 at 21:58
  • Thanks @sfdxfox I'll have to give some thought to my billing strategy
    – Maddix
    Apr 19 at 22:32

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.