function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

Callout to retrieve Report List from my managed VisualForce page

I am trying to retrieve the XML containing the list of Reports for my Organization using the document available at https://<server>


The way I'm retrieving this document from inside my VF controller is with this code:


Map<String, String> headers = ApexPages.currentPage().getHeaders();
String endpoint = 'https://' + headers.get('Host') + '/servlet/servlet.ReportList';
HttpRequest req = new HttpRequest();
req.setHeader('Cookie','sid=' + UserInfo.getSessionId());
Http http = new Http();
HttpResponse res = http.send(req);
reportBody = res.getBody();


This works fine for an Unmanaged VisualForce page ... but when I deploy my VF page in a Managed Package, this breaks down. The issue is that when you access a managed VF page, there is a big long redirection dance that issues you new cookies (and a new Session ID) for the server that the VF page resides at. The URL you finally end up at is a URL (ex. https://<package prefix>.<server name><my page>)


So, there are two issues:


1) The use of the headers.get('Host') is no longer correct (since I'm no longer at <server> ... I can work around that because SF actually gives me a Redirect response if I try to run the above code


2) The Session ID inside my VF controller is not a valid SessionID for the <server> server. This is what I can't figure out a workaround for.


Is there some way to have SF issue me a SessionID via some API that would be valid for the <server> based on the SessionID I have for the domain?




Paulo CastroPaulo Castro



 Im having a very similar issue. The only difference is that Im calling another VF page (that prints JSON strings).

 Did you find the solution?


 Best regards





Not a good one. The only solution I could find was to create a S-Control and in the body of the S-Control, use the merge variable {!Api.Session_ID} and create a link to my VF page that passes the SessionID on the URL. This means that my app needs to contain this interim S-Control whose sole purpose is to create a set of links with the SessionID