function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
nschwennschwen 

How to ID a sandbox in Custom Links?

Hi! 

 

I have a custom link that points to an external URL.  I wan to pass a parameter on the URL that tells me when the request is coming from a sandbox vs. our production SFDC environment (so I can handle the request differently).  I'm trying to do this by adding a merge field to the URL, but can't find any available fields that would help me.  I was hoping for something like 'Sandbox Name' or 'Site URL', but really am interested in anything that would help me tell what environment the call comes from.

 

I am doing this currently by hard coding the URL, but the problem is that whenever we refresh our sandbox from production, the production hard coded URL is copied down to the sandbox, and I have to remember to change it manually.  I was thinking a merge field would be a better solution, if I can find something useful.  But I'm open to other ways to do this too.

 

Thanks in advance for your help!

 

Best Answer chosen by Admin (Salesforce Developers) 
pankaj.raijadepankaj.raijade

one more option is available

Please check 

 

{!$Api.Enterprise_Server_URL_190}

 

Let me know if this works?

All Answers

pankaj.raijadepankaj.raijade

There are many ways to do this.

 

you can user {!$Site.CurrentSiteUrl} in URL formula 

or 

you can use custom setting and use it in URL  but you will have to change it in sandbox every time you refresh it.

 

Regards,

Pankaj Raijade.

nschwennschwen

Hi Pankaj,

 

Thanks for the reply!  I tried using the {!$Site.CurrentSiteUrl} merge field, but it unfortunatly seems to be empty.  I'm succesfully using other merge fields in the URL, but all the $Site fields I've tried return no values. 

 

The custom setting is what I'm using today, but as you said, it needs to be manually changed in the sandbox every time it's refreshed, which is what I'm hoping to avoid.

 

Any other ideas, or thoughts on why the $Site parameters all return no values for me?  Below is the custom URL with merge fields I'm testing, and the result I see when using it.  You'll see I'm getting values for the first two parameters, but nothing for the $Site fields.

 

 

Thank you for any help!

 

 

Custom URL String: 

http://Testaaa.com?Site_Domain={!$ObjectType.SiteDomain}&User_Name={!$User.Username}&URL={!$Site.CurrentSiteUrl}&OrigURL={!$Site.OriginalUrl}&Custom={!$Site.CustomWebAddress}&Name={!$Site.Name}

 

What I get when running it from a link on the home tab (personal values editied):

http://testaaa.com/?Site_Domain=9I9&User_Name=my.name%40sample.com&URL=&OrigURL=&Custom=&Name=

 

 

pankaj.raijadepankaj.raijade

one more option is available

Please check 

 

{!$Api.Enterprise_Server_URL_190}

 

Let me know if this works?

This was selected as the best answer
pankaj.raijadepankaj.raijade

If above option does not work.

 

There is a work around possible

send user name field which will contain your sandbox name at the end.

 

And you can differentiate from where the request is coming.

 

Regards,

Pankaj Raijade.

 

nschwennschwen

 

That did it!  {!$Api.Enterprise_Server_URL_190} returns the calling URL, plus some extra path information that I didn't really need.  I ultimately went with the following, to trim it back to the relevant information:

 

  http://Testaaa.com?Server={!LEFT($Api.Enterprise_Server_URL_190,(FIND('/services',$Api.Enterprise_Server_URL_190)-1))}

 

I had also considered your suggestion of looking at the end of the user name.  It's just a little problematic as we have a variety of user name formats in production that would make it challenging to parse the name correctly (though not impossible).  However, your solution above it much cleaner, so I'm going with that. 

 

Thank you very much for your help!!