How can I determine which Salesforce instance sent an unhandled exception email based on the contents of the email?

The Organization Id (keyprefix 00D) and User Id (keyprefix 005) are at the start of the email body. E.g.

Apex script unhandled exception by user/organization: 00540000000000F/00D400000000001

However, I don't always know which of the multiple orgs I can connect to these Ids belong to.

The organization name does appear in the email subject, but in this particular case it is something obscure like

"Developer script execution from Web : "

I've started keeping a spreadsheet to map the Organization Id to the instances, but is there any alternative approach?

After writing this out I might be asking too much. I can't think of much more than the Org Name, Org Id, and possibly server instance that could be used to identify the Salesforce instance. Happy to be proven wrong though.


Is this for a managed package? If so there are tools available that you can use to keep records of orgIds to customers.

First and foremost is the license management app, which generates a new custom object record and lead for every install of your app. You can use the information from the lead to keep track of what is installed where.

There's also the partner black tab/subscriber support route, which gives you access to customer orgs via the "Grant Login Access" menu, just like SFDC support gets. The admin side of this allows you to lookup customer orgs by orgId.


Dan One of the problems is when you refresh the box will it not change the instance? How will you update your spreadsheet?

I just found from the link that system.debug('###'+URL.getSalesforceBaseUrl().toExternalForm()); would give you the instance of the org :) (pretty sweeet find )

http://boards.developerforce.com/t5/Apex-Code-Development/Determine-SalesForce-instance-or-URL-in-code/td-p/84662 Thanks to cloudnine \m/

  • Yes, I found that the Sandbox OrgId had changed due to a refresh and hence I wasn't able to look it up in my spreadsheet. – Daniel Ballinger Sep 24 '12 at 20:50
  • Did the URL object reference help ? salesforce.com/us/developer/docs/apexcode/Content/… – Rao Sep 24 '12 at 20:52
  • I'd need to catch and handle the exception to be able to include that apex code. While helpful, it doesn't address the issue of determining the instance that caused the unhandled exception. – Daniel Ballinger Sep 24 '12 at 20:54

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.