+ Start a Discussion
infoweldernickinfoweldernick 

salesforce instance server url in a trigger

We are attempting to use a trigger to create a FeedPost of type LinkPost that will update the User's status and provide a link to a salesforce record.  This trigger will be packaged and distributed to orgs across many salesforce.com instances (nax, emea, apac, sandbox, etc), so we need to make the server url in the link dynamic based on the org's location.

 

Since we are only using a trigger in this package, there are no VF pages to capture the url and store it.  We could go that route, but are trying to avoid it.

 

Our best solution so far has been to build our url based on a formula field on the object from which the trigger is fired:

 

SUBSTITUTE(LEFT($Api.Enterprise_Server_URL_180, FIND("salesforce.com", $Api.Enterprise_Server_URL_180)-1), "-api", "")

 

This works well for NA instances, but for emea, the Enterprise Server URL is "eu", so the links created with this formula are invalid for emea users.

 

I'm looking for some best practices from the community as to how you all would address this problem.  Thanks in advance for any feedback.

 

 

SuperfellSuperfell

Can't you just use a relative URL ?

SanchSanch

I just did something similar yesterday. But not for a trigger, but within an apex class(controller).  Not sure if this will work, but I thought I would share it with you. Let us know how u implemented at the end. Thanks.

 

ApexPages.currentPage().getHeaders().get('Host')

 

 

finalistfinalist

I used the following in a LinkPost:

 

String retURL = ApexPages.currentPage().getHeaders().get('Host');
fpost.linkURL = retURL + '/' + <SObject.Id>;

 

This works, if you don't mind forcing the user to log in again - it doesn't retain the user's credentials

SAKTHIVEL MSAKTHIVEL M

HI,
You can get the Salesforce URL using Triggers,
Please check it below link,
http://theblogreaders.com/how-to-get-the-salesforce-instance-server-url-from-apex-trigger/

 

TheBlogreaders.com
Blog | Salesforce Certified Administrator | Salesforce Certified Developer