• topartnr
  • NEWBIE
  • 0 Points
  • Member since 2009

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 0
    Replies

Hi,

 

I'm writing Apex trigger that needs to compose a URL to a dynamically created custom object.

Since I don't want to hard code the URL of the Salesforce instance and also don't want to change the code when switching between Sandbox and Prod org's, I'm looking for a way to find out from within Apex code which Salesforce instance it's running in.

So, for example, this code should return 'https://cs2.salesforce.com' when running in a Sandbox and 'https://na2.salesforce.com' when running in Prod.

I've noticed that Sandbox Id's start with 00DR whereas Prod Org IDs start with 00D<some digit>. But am not sure if this is something that can be used to identify the instance or if there is any better way.

 

Thanks.