I been trying to get my Session ID Parameters into my Apex class so that I can retrieve a Picture from inside Salesforce and send it out to Facebook.
But I'm not sure why I'm not getting my Session ID Can someone help me?
I been using this 2 posts as reference.
VisualForce Page Code
<apex:page controller="GetChart" showHeader="true" sideBar="true" >
<apex:includeScript value="https://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.9.1.min.js"/>
<apex:includeScript value="https://ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js" />
<script type="text/javascript">
function chk123() {
jQuery('[id$=myHiddenField]').val('{!GETSESSIONID()}');
passSessionParameters();
}
</script>
<apex:sectionHeader title="Attach Documents"/>
<apex:form enctype="multipart/form-data" id="theform">
<apex:pageMessages />
<apex:pageBlock title="Upload a Attachment">
<apex:inputHidden value="{!myString}" id="myHiddenField"/>
<apex:actionFunction name="passSessionParameters" action="{!exInt}" rerender="myHiddenField"/>
<apex:pageBlockButtons >
<apex:commandButton value="Save" onclick="chk123();"/>
</apex:pageBlockButtons>
<apex:includeScript value="/soap/ajax/29.0/connection.js"/>
<apex:includeScript value="/soap/ajax/29.0/apex.js"/>
<script type="text/javascript">
var __sfdcSessionId = '{!GETSESSIONID()}';
var oResult = sforce.connection.query(query);
var oDocuments = oResult.getArray('records');
</script>
<apex:outputPanel rendered="{!bolClose}">
<script>
alert("{!aId}");
self.close();
opener.location.href = "/apex/Upload_Attachment?id="+"{!aId}";
</script>
</apex:outputPanel>
</apex:pageBlock>
</apex:form>
</apex:page>
Apex Class Page
public with sharing class GetChart{
public String aId { get; set; }
public Boolean bolClose { get; set; }
public String objAtt { get; set; }
public String resume { get; set; }
public String intSize { get; set; }
public String strFileName { get; set; }
public String myString {get; set;}
public GetChart(){
myString = '';
}
public PageReference exInt() {
bolClose = false;
String chart_1 ='https://ap4.salesforce.com/servlet/servlet.ChartServer?r....';
String base64Data;
httprequest req = new httprequest();
req.setEndpoint(chart_2);
req.setmethod('GET');
req.setHeader('Cookie', 'sid=' + myString + ';'); //UserInfo.getSessionId()+ ';');
system.debug('@@sid ' + myString);
system.Debug('@@Session = ' + UserInfo.getSessionId());
http http = new http();
httpresponse res = http.send(req);
Blob image = res.getBodyAsBlob();
base64Data = EncodingUtil.base64Encode(image);
Document docatt = new Document();
docatt.Name = 'Chart 1.jpg';
docatt.Body = EncodingUtil.base64Decode(base64Data);
docatt.FOLDERID = '42l6F03184wqNi'; //Your folder id
docatt.IsPublic = true;
insert docatt;
return null;
}
}
UserInfo.getSessionId()
but it didn't work