Reply
Visitor
BritoAlfonso
Posts: 2
Accepted Solution

Invalid Session Id using Flex

Hello I am Newbie with Salesforce, sorry if this is a very easy question

 

We developed and application with flex, and now we are trying to connect it to SalesForce:  we created the ApexPage:

<apex:page sidebar="false" showHeader="false" standardController="Oferta__c">
<apex:flash src="{!$Resource.CO}" height="100%" width="100%"
flashvars="sessionId={!$Api.Session_ID}&urlServidor={!$Api.Partner_Server_URL_150}&idOferta=a09S0000000925WIAQ&idOpportunity="/>
</apex:page>

 

 

We created a Custom Buttom that called the  Previus VisualForce Page

 

We added the Buttom to the Format Page

 

And we are getting the following error when we clicked on the buttom:

[SWF] /resource/1256553573000/CO - 3.969.554 bytes after decompression
App Domain = null
Api Server name = c.cs1.visual.force.com
loading the policy file: http://c.cs1.visual.force.com/services/Soap/cross-domain.xml

loginWithSessionId(
 sid: 00DS0000000FP4X!AR12345gD59GORSzw.7LHejW4Zz.aAmtfnluH_4Y1PnuQtPm_q9JF1ZQZiyL27ePS2tkpIjQ5ozRSGPc47r0zYz5bhn..7Qk
 surl: https://c.cs1.visual.force.com/services/Soap/u/15.0/00DSaqzwed0FolkX
);
App Domain = c.cs1.visual.force.com
Api Server name = c.cs1.visual.force.com
loading the policy file: http://c.cs1.visual.force.com/services/Soap/cross-domain.xml
transport.url = http://c.cs1.visual.force.com/services/Soap/u/15.0/
00DSaqzwed0FolkX
Method name is: getUserInfo
Method name is: getUserInfo
responseType: Fault
Saleforce Soap Fault: sf:INVALID_SESSION_ID
INVALID_SESSION_ID: Invalid Session ID found in SessionHeader: Illegal Session

 

But that is the session Id that we are getting through the API

 

On S-Controls we used the 

sessionId={!$Api.Session_ID}

And it is working OK

 

If you have any suggest, it will be wellcome

 

Thanks in advance

 

 

Moderator
DevAngel
Posts: 3,214

Re: Invalid Session Id using Flex

This actually seems to be a bug for the apex:flash component.  If you use the standard html object/embed tag it will work properly.

 

Not sure when the fix will be in for for this.

 

 

Cheers,

 

Dave
Developer Evangelism
BLOG - blog.sforce.com

Follow me on twitter @dcarroll
Regular Contributor
rajarak
Posts: 23

Re: Invalid Session Id using Flex

Give this a try ..

It might work

 

<apex: page>

<apex:includescript value="/soap/ajax/15.0/connection.js" />

 

<script>

 

window.onload = setSessionId;

 

function setSessionId(){

sforce.connection.sessionId = '{!$Api.Session_ID}';

 

}

 

</script> 

 

YOUR code here...

 

</apex:page> 

Regular Contributor
eto
Posts: 53

Re: Invalid Session Id using Flex

We had that problem several times in several orgs and what we found out is this: The Session ID you receive from the API global variable can be different from the session ID which you really have on visual force pages. I'm not sure, but I think it happens if a VF page switches to a different server (visual.force.com instead of salesforce.com).

 

To solve this, you need to get the session from a Controller or Extension instead of the API global variable:

 

A very simple Extension:

 

public class GetSessionControllerExtension {

private final SObject myObject;

public GetSessionControllerExtension(ApexPages.StandardController stdController) {
this.myObject = stdController.getRecord();
}

public String GetMySessionId() {
return UserInfo.getSessionId();
}

}

 

Just add it to your VF page, then you can use flashvars="sessionId={!sessionId}&..." to receive a working sessionId for your Flex application:

<apex:Page sidebar="false" showHeader="false" standardController="Oferta__c" extensions="GetSessionControllerExtension">
<apex:flash src="{!$Resource.CO}" height="100%" width="100%"
flashvars="sessionId={!sessionId}&urlServidor={!$Api.Partner_Server_URL_150}&idOferta=a09S0000000925WIAQ&idOpportunity="/>
</apex:Page>

 

 

 

This approach fixed our problem however we are still wondering how such a feature bug can remain for such a long time without being documented (feature) or fixed (bug).

 

hth

Ingo