Get the URL Root in a Formula
If you are creating links in a formula, you want them to work in sandboxes.
If you have a URL like:
https://myOrg--sbox.sandbox.my.salesforce.com
If you use:
"https://" & mid($Api.Enterprise_Server_URL_500,9,(FIND("/",$Api.Enterprise_Server_URL_500 ,9)-8))
You will get:
https://myorg--sbox.sandbox.my.salesforce.com/
Or, for Communities,
"https://" & mid($Api.Enterprise_Server_URL_500,9,(FIND("/",$Api.Enterprise_Server_URL_500 ,9)-8)-15)&"site.com"
Note: For Communities if you have a custom domain you should first check for whether you are in production, because your custom URL won't fit the pattern.
This works by:
- Start with the literal string "https://"
- Find the mid substring where:
- The URL is the Enterprise Server URL
- Starting at location 9 (after https://)
- For length
- Using FIND
- Find the first slash after location 9
- subtracting 8 characters for https://
- In the Community version, we pull out the "salesforce.com" by backing out 15 further characters and manually appending "site.com".
Comments
Post a Comment