Thomas Hoban - 10 years ago
I'm shocked that there isn't a good way to do this. I have a use case where I need to identify the server in a batch program. The batch sends emails using Visual Force Email templates that contain references to some images. We need to provide the full url for the image.
M. J. Kahn - 10 years ago
A Chatter FeedPost's LinkURL field requires a full URL. If you're creating a FeedPost outside the context of a VF page (so you don't have access to a PageReference), there's no good way to get the current org's Salesforce instance, so you can't construct a full URL, at least not without resorting to some ugly custom workaround.
Arvind Kaul - 10 years ago
A typical API Server URL in a dev sandbox appears as "https://c.cs3.visual.force.com/services/Soap/c/18.0/00DQ0000000AgYM", where the record ID is ORG ID.
I am generating this API Server URL in my APEX class using "ApexPages.currentPage().getHeaders().get('Host')", which gives the instance server url "c.cs3.visual.force.com". Then I use two other constants to form the actual API Server URL, which is "https://" and "services/Soap/c/18.0".
API Server URL= 'https://'+ 'ApexPages.currentPage().getHeaders().get('Host')' +'services/Soap/c/18.0/'+ORG_ID
I believe there should be a robust way to retrieve API Server Url in APEX class or trigger then going via such workarounds, and expect Salesforce to come up with some solution in coming releases.