You need to sign in to do that
Don't have an account?

How to get Session ID and Server url from Visual force page to Controller class when page loads
I need to set Session ID and Server URL when page loads in controller class. This is required to call external synchronous web service call
Check out this blog post.
right now i am using this blog post only, here i need to click the output text field to get server url and session id, what i need is something like on page load without clicking anything on page. I mean when page loads first time i need to get server url and session id.
is there any way or woraround for my requirement..
*Bump*
Working on this same issue right now. To further complicate this I 'm have a component that need to get this info and I'd really not require user interaction. Any suggestions?
<script> var btnCopy = document.getElementById("{!$Component.lk}"); </script>
<script>
window.onload = new function() { btnCopy.click(); };
</script>
Thanks for the suggestion but I took a different route using the onload event. The following works in a VF page;
<apex:page setup="true" controller="MyController" showHeader="true"> <apex:form> <apex:actionFunction name="getAPIParams" id="getAPIParams" action="{!dologin}" reRender="theForm" > <apex:param name="sessionId" assignTo="{!apiSessionId}" value="{!$Api.Session_ID}" /> <apex:param name="serverURL" assignTo="{!apiServerURL}" value="{!$Api.Partner_Server_URL_140}" /> </apex:actionFunction> <script language="JavaScript"> window.onload = function() { getAPIParams();} </script> </apex:form> </apex:page>
public class MyController { public String apiSessionId {get;set;} public String apiServerURL {get;set;} public PageReference doLogin(){ System.debug('apiSessionId: ' + apiSessionId); System.debug('apiServerURL: ' + apiServerURL); return null; } }
Check the System Log to verify the outputs. It also seems to work when nested in a component using the same controller.
<apex:page setup="true" showHeader="true"> <c:testServerParams /> </apex:page>
<apex:component controller="MyController"> <apex:form > <apex:actionFunction name="getAPIParams" id="getAPIParams" action="{!dologin}" reRender="theForm" > <apex:param name="sessionId" assignTo="{!apiSessionId}" value="{!$Api.Session_ID}" /> <apex:param name="serverURL" assignTo="{!apiServerURL}" value="{!$Api.Partner_Server_URL_140}" /> </apex:actionFunction> <script language="JavaScript"> window.onload = function() { getAPIParams();} </script> </apex:form> </apex:component>
Thanks for the above code. There's a bug in it; you need to set the id of form element to theForm.
Is there any standard methods to retrive the apiSessionId and apiServerURL values directly in class.