Constructing the Correct Salesforce.com URL?

April 23rd, 2009

I’ve seen this question on the Salesforce.com message boards but have never seen an answer so I thought I would post it here. Here’s my dilema… we are writing some customization that requires us to construct the URL to a Salesforce.com record (e.g. https://na5.salesforce.com/02u300000000ACi) and send it via email. I’ve seen a solution to this using Visualforce but never in Apex.

Here is what I came up with but it seems that there must be a better way. The only constant that I could come up with is our Production org ID. So my Apex class holds a reference to this ID and then I have a method that checks the current user’s org ID and constructs the URL.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
 
public class MyCustomClass {
 
    // set the production org id so we can see what system we are on
    private static final String PRODUCTION_ORG_ID = '00Z990000001ZZZ';
 
    // returns the correct system url for the current org
    private String orgUrl {
        get {
            return UserInfo.getOrganizationId() == PRODUCTION_ORG_ID ? 'http://na5.salesforce.com' : 'http://cs1.salesforce.com';
        }
        set;
    }
 
    // write some code that calls orgUrl....
 
}
  • Share/Bookmark

Related posts:

  1. Developing Salesforce.com Applications with Flex and Visualforce
  2. Preventing Recursive Future Method Calls in Salesforce
  3. DOT a Salesforce Developer Org
  4. How to deploy Apex without test coverage (part 2)
  5. Salesforce.com Licenses

Categories: Apex, Salesforce

Leave a comment

Comments Feed1 Comment

  1. Jesse Lorenz

    Jeff, here are a couple of work-arounds:

    http://ideas.salesforce.com/article/show/10091004/Apex_method_to_identify_salesforcecom_server

    http://community.salesforce.com/sforce/board/message?board.id=Visualforce&thread.id=7697&view=by_date_ascending&page=1

Leave a comment

Feed

http://blog.jeffdouglas.com / Constructing the Correct Salesforce.com URL?