You need to sign in to do that
Don't have an account?
vfDeveloper.ax341
I need to acces Partner server url global variable from apex code in order to pass it into web service.
In visualforce i can write the followin statement in page layout {!$Api.Partner_Server_URL_120} which renderes something like that https://na5.salesforce.com/services/Soap/u/12.0/461200D70000000IfeF
How can i access {!$Api.Partner_Server_URL_120} variable from apex code?
Thanks in advance
Accessing partner server url from apex code
I need to acces Partner server url global variable from apex code in order to pass it into web service.
In visualforce i can write the followin statement in page layout {!$Api.Partner_Server_URL_120} which renderes something like that https://na5.salesforce.com/services/Soap/u/12.0/461200D70000000IfeF
How can i access {!$Api.Partner_Server_URL_120} variable from apex code?
Thanks in advance
If you using visualforce controller, you can try following code
String url = ApexPages.currentPage().getHeaders().get('Host');
Two options
on a std controller environment
another way is to create a custom formula field somewhere usefull, and the return as text
$Api.Partner_Server_URL_260
cheers.
I searched for this subject hoping that with all the updates of apex by now there would be a cleaner way to access this. I have been using over the years a component with a static property containing the url, I can then use the static property eslewhere. I just include the component in the pages where I use the variable to assign it
the controller just has a static property
and in pages where I know that some other aprt of my code requires the url, I include the component with the correct assignment
I hope this can be of help to someone searching for this, as apparantly Salesforce has no intention of providing access to these urls in apex code (I see several posts with the same question and this thread for example dates from 5 years ago
in context, like batch process, triggers, @Future methods, etc ...
The way I do it, and maybe someone have something better, is like this.
I create a formula field in the user: API_URL__c and the formula will
return a text: $Api.Partner_Server_URL_260
then in any apex context you can always do:
String url = [select API_URL__c from User where id=:userinfo.getUserId()].
API_URL__c;
Cheers.
--
Federico Larsen
Mobile: +34644590488
Phone: +34917400957
U.K. : +442070973946
Twitter/Skype: larsenfed
LinkedIn: http://www.linkedin.com/in/federicolarsen
Blog: http://larsenfed.wordpress.com
You should use Dropbox , it's free!