My very first thought was NO.
But after having said that syllable, I understood that this could be possible, using an HTTP GET call + cookies + correct resource URL.
This is the solution I came into:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | Http h = new Http(); HttpRequest request = new HttpRequest(); request.setEndpoint(URL.getSalesforceBaseUrl().toExternalForm()+ 'resource/ZIPPEDRESOURCE/file.ext' ); request.setMethod( 'GET' ); request.setHeader( 'Cookie' , 'sid=' +UserInfo.getSessionId()+ ';' ); request.setTimeout( 60000 ); HttpResponse request = h.send(request); if (request.getStatusCode() != 200 ){ //handle the error throw new CustomException( 'Unable to load resource' ); } //now you can get the content String fileContent = request.getBody(); //or Blob fileContentAsBlob = request.getBodyAsBlob(); |
The last thing to do is to enable your instance URL from Setup > Remote Site Settings, allowing https://xxx.salesforce.com but also I suggest https://c.xxx.visual.force.com and wathever it makes sense (there could be some URL path I haven't though to).
No surprise that this could be used to get any resource in the CRM (with the proper URL handling).
No comments:
Post a Comment