Accessing Session Id and API Server URL parameters with Visualforce


/ Published in: Other
Save to your folder(s)

Credits to Andrew Albert


Copy this code and paste it in your HTML
  1. Visualforce Page
  2. <apex:page setup="true" controller="MyController" showHeader="false">
  3. <apex:form >
  4. <apex:outputpanel id="counter">
  5. <apex:outputText value="Click Here To Generate Session Id and Server URL" />
  6. <apex:actionSupport event="onclick" action="{!doLogin}" rerender="refreshId" status="counterStatus">
  7. <apex:param name="sessionId" assignTo="{!apiSessionId}" value="{!$Api.Session_ID}" />
  8. <apex:param name="serverURL" assignTo="{!apiServerURL}" value="{!$Api.Partner_Server_URL_140}" />
  9. </apex:actionSupport>
  10. </apex:outputpanel><br></br>
  11. <apex:outputPanel id="refreshId">
  12. <apex:outputText value="API Session Id: {!apiSessionId}"/><br></br>
  13. <apex:outputText value="API Server URL: {!apiServerURL}"/><br></br>
  14. </apex:outputPanel>
  15. </apex:form>
  16. </apex:page>
  17.  
  18.  
  19. Controller Apex Class
  20. public class MyController {
  21.  
  22. public String apiSessionId {get;set;}
  23. public String apiServerURL {get;set;}
  24.  
  25. public PageReference doLogin(){
  26. System.debug('apiSessionId: ' + apiSessionId);
  27. System.debug('apiServerURL: ' + apiServerURL);
  28. return null;
  29. }
  30.  
  31. }

URL: http://blog.sforce.com/sforce/2009/01/accessing-session-id-and-api-server-url-parameters-with-visualforce.html

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.