Skip to content

Instantly share code, notes, and snippets.

@macanderson
Created December 29, 2011 05:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save macanderson/1532031 to your computer and use it in GitHub Desktop.
Save macanderson/1532031 to your computer and use it in GitHub Desktop.
Apex Get Current URL Method
/**
* @description Various Apex methods for working with URLs
*
* @author Mac Anderson
*
* @version 1.0
*
* @moreinfo http://macscloud.com
*/
public class UrlMethods {
String BaseUrl; // The Url w/o the page (ex: 'https://na9.salesforce.com/')
String PageUrl; // The Url of the page (ex: '/apex/SomePageName')
String FullUrl; // The full Url of the current page w/query string parameters
// (ex: 'https://na9.salesforce.com/apex/SomePageName?x=1&y=2&z=3')
String Environment; // Writing code that can detect if it is executing in production or a sandbox
// can be extremely useful especially if working with sensitive data.
public UrlMethods() { // Constructor
BaseUrl = URL.getSalesforceBaseUrl().toExternalForm(); // (Example: 'https://na9.salesforce.com/')
}
}
@macanderson
Copy link
Author

/**

public class UrlMethods {

String BaseUrl;         // The Url w/o the page (ex: 'https://na9.salesforce.com/')

String PageUrl;         // The Url of the page (ex: '/apex/SomePageName')

String FullUrl;         // The full Url of the current page w/query string parameters 
                        // (ex: 'https://na9.salesforce.com/apex/SomePageName?x=1&y=2&z=3')

String Environment;     // Writing code that can detect if it is executing in production or a sandbox
                        // can be extremely useful especially if working with sensitive data.

public UrlMethods() {   // Constructor

    BaseUrl = URL.getSalesforceBaseUrl().toExternalForm(); // (Example: 'https://na9.salesforce.com/')

}

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment