You need to sign in to do that
Don't have an account?
kminev
Get server url in Apex code
Hi,
I know this has been posted before, but I have't found a solution to my question.
I need to able to get the server url via apex code. For example: https://tapp0.salesforce.com/
Is there a call that does that already and if not are there any work-arounds?
Thank you very much.
Hi, here is the code:
public static String getDomain () { String hostname = ApexPages.currentPage().getHeaders().get('Host'); String domain = 'https://' + hostname + '/apex'; return domain; }
I hope help you.
J.
All Answers
Hi, here is the code:
public static String getDomain () { String hostname = ApexPages.currentPage().getHeaders().get('Host'); String domain = 'https://' + hostname + '/apex'; return domain; }
I hope help you.
J.
Hi,
You won't be able to get access to any 'apexpages' stuff within the trigger. It is not guaranteed that the trigger is being fired from a web request - could be from data loader, workflow etc...
Can I ask why you need the server url??
If you do need it you can always store it in a custom object (or custom setting) and pull it out when required within the trigger. This would have to be done within an apex page controller.
Regards,
R.
The reason why I need the url is to embed url link in my email body that I am sending from apex class/trigger.
For example myUrs + caseId
Thanks
Fair enough....
You could create a static parameter which holds the url value that is populated via a controller somewhere else. You'd just need to make sure the parameter is populated before you need to use it. Alternatively, stick it in a custom object.
Can't think of anyother sensible ways to do it. Perhaps someone else has some ideas???
R.