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
patelankurbpatelankurb 

Salesforce Authentication error while passing flashvars from VF to Flex grid

Hi,

 

I have created Flex grid, on while I want to populate Account sObject's data.

 

Code of mxml file, After successful build, I have uploaded .swf file into static resource.

<?xml version="1.0" encoding="utf-8"?> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" xmlns:salesforce="http://www.salesforce.com/" creationComplete="login(event)"> <salesforce:Connection id="apex" serverUrl="https://www.salesforce.com/services/Soap/u/9.0" /> <mx:Script> <![CDATA[ import mx.collections.ArrayCollection; import com.salesforce.results.QueryResult; import mx.utils.ObjectUtil; import mx.controls.Alert; import com.salesforce.AsyncResponder; import com.salesforce.objects.LoginRequest; private function login(event:Event):void { var lr:LoginRequest = new LoginRequest(); // lr.server_url = parameters.surl; // lr.session_id = parameters.sid; Alert.show(parameters.session_id); Alert.show(parameters.server_url);

// session_id and serverurl is giving authentication error in Firefox, IE, Safari

lr.session_id = parameters.session_id; lr.server_url = parameters.server_url;

 // username and password is working fine only in Firefox, and IE, Safari gives connection error

/* lr.username = "SFDC_username" lr.password = "SFDC_password"; */

 

lr.callback = new AsyncResponder(loadData, handleFault); apex.login(lr); } [Bindable] private var accountList:ArrayCollection = new ArrayCollection(); private function handleFault(fault:Object):void { Alert.show(ObjectUtil.toString(fault)); } private function loadData(lr:Object):void { apex.query("Select Name, Phone, Type From Account", new AsyncResponder( function(qr:QueryResult):void { if (qr.size > 0) { accountList = qr.records; } }, handleFault) ); } ]]> </mx:Script> <mx:DataGrid dataProvider="{accountList}" left="10" right="10" top="10" bottom="10"> <mx:columns> <mx:DataGridColumn dataField="Name"/> <mx:DataGridColumn dataField="Phone"/> <mx:DataGridColumn dataField="Type"/> </mx:columns> </mx:DataGrid> </mx:Application>

 

Visualforce page code (SimpleFlexGrid.page):

<apex:page > <!-- Begin Default Content REMOVE THIS --> <h1>Congratulations</h1> This is your new Page: SimpleFlexGrid <!-- End Default Content REMOVE THIS --> <apex:flash id="flexSOs" src="{!$Resource.SimpleFlexGrid}" height="100%" width="100%" flashvars="session_id={!$Api.Session_ID}&server_url={!$Api.Partner_Server_URL_90}"/> </apex:page>

 

While loading  /apex/SimpleFlexGrid page, I am  following error;

 

(com.salesforce.results::Fault)#0
  context = (null)
  detail = (Object)#1
    fault = (Object)#2
      exceptionCode = "INVALID_SESSION_ID"
      exceptionMessage = "Invalid Session ID found in SessionHeader: Illegal Session"
      xsi:type = "sf:UnexpectedErrorFault"
  faultcode = "sf:INVALID_SESSION_ID"
  faultstring = "INVALID_SESSION_ID: Invalid Session ID found in SessionHeader: Illegal Session"

 

 

Flashvars in apex:flash tag gives above error in all browser.

 

But if I remove flashvars, and hardcode username, and password in actionScript, everything is working fine except in safari browser.

 

Any help on flashvars session_id, server_url would be appreciated.

 

Thanks,

Ankur

 

Best Answer chosen by Admin (Salesforce Developers) 
arunkarunk

Hi Ankur,

 

I got your code working with a little modification.

 

First of all, flashvars="session_id={!$Api.Session_ID}&server_url={!$Api.Partner_Server_URL_90}" dosent work for me. I never get value of $Api.Session_ID, so i use a workaround for this,

 

Create a apex class as below

public class GetSessionControllerExtension { public GetSessionControllerExtension(ApexPages.StandardController stdController) { } public String GetMySessionId() { return UserInfo.getSessionId(); } }

 

The GetMySessionId() function of the class returns the needed session ID.

 

Then, modify the VisualForce page as below :

 

<apex:page standardController="Lead" extensions="GetSessionControllerExtension"> <apex:pageBlock title="Salesforce Login Checker"> <apex:flash src="{!$Resource.test5}" width="100%" height="800" flashvars="sid={!MySessionId}&surl={!$Api.Partner_Server_URL_90}"/> </apex:pageBlock> </apex:page>

 

Here, I hav added the class GetSessionControllerExtension as an extension accessed session id as flashvars="sid={!MySessionId}&surl={!$Api.Partner_Server_URL_90}"

 

 

Also, modified code for your MXML application

 

<?xml version="1.0" encoding="utf-8"?> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" xmlns:salesforce="http://www.salesforce.com/" creationComplete="login()"> <salesforce:Connection id="apex" serverUrl="https://www.salesforce.com/services/Soap/u/9.0" /> <mx:Script> <![CDATA[ import mx.collections.ArrayCollection; import com.salesforce.results.QueryResult; import mx.utils.ObjectUtil; import mx.controls.Alert; import com.salesforce.AsyncResponder; import com.salesforce.objects.LoginRequest; private function login():void { var lr:LoginRequest = new LoginRequest(); lr.session_id = parameters.sid; lr.server_url = parameters.surl; lr.callback = new AsyncResponder(loadData, handleFault); apex.login(lr); } [Bindable] private var accountList:ArrayCollection = new ArrayCollection(); private function handleFault(fault:Object):void { Alert.show(ObjectUtil.toString(fault)); } private function loadData(lr:Object):void { apex.query("Select Name, Phone, Type From Account", new AsyncResponder( function(qr:QueryResult):void { if (qr.size > 0) { accountList = qr.records; } }, handleFault) ); } ]]> </mx:Script> <mx:DataGrid dataProvider="{accountList}" left="10" right="10" top="10" bottom="10"> <mx:columns> <mx:DataGridColumn dataField="Name"/> <mx:DataGridColumn dataField="Phone"/> <mx:DataGridColumn dataField="Type"/> </mx:columns> </mx:DataGrid> </mx:Application>

 

 

I have removed the login function parameter, but the code should work fine with it also..

 

 

The code is working fine for me after these changes...

All Answers

arunkarunk

Hi Ankur,

 

I got your code working with a little modification.

 

First of all, flashvars="session_id={!$Api.Session_ID}&server_url={!$Api.Partner_Server_URL_90}" dosent work for me. I never get value of $Api.Session_ID, so i use a workaround for this,

 

Create a apex class as below

public class GetSessionControllerExtension { public GetSessionControllerExtension(ApexPages.StandardController stdController) { } public String GetMySessionId() { return UserInfo.getSessionId(); } }

 

The GetMySessionId() function of the class returns the needed session ID.

 

Then, modify the VisualForce page as below :

 

<apex:page standardController="Lead" extensions="GetSessionControllerExtension"> <apex:pageBlock title="Salesforce Login Checker"> <apex:flash src="{!$Resource.test5}" width="100%" height="800" flashvars="sid={!MySessionId}&surl={!$Api.Partner_Server_URL_90}"/> </apex:pageBlock> </apex:page>

 

Here, I hav added the class GetSessionControllerExtension as an extension accessed session id as flashvars="sid={!MySessionId}&surl={!$Api.Partner_Server_URL_90}"

 

 

Also, modified code for your MXML application

 

<?xml version="1.0" encoding="utf-8"?> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" xmlns:salesforce="http://www.salesforce.com/" creationComplete="login()"> <salesforce:Connection id="apex" serverUrl="https://www.salesforce.com/services/Soap/u/9.0" /> <mx:Script> <![CDATA[ import mx.collections.ArrayCollection; import com.salesforce.results.QueryResult; import mx.utils.ObjectUtil; import mx.controls.Alert; import com.salesforce.AsyncResponder; import com.salesforce.objects.LoginRequest; private function login():void { var lr:LoginRequest = new LoginRequest(); lr.session_id = parameters.sid; lr.server_url = parameters.surl; lr.callback = new AsyncResponder(loadData, handleFault); apex.login(lr); } [Bindable] private var accountList:ArrayCollection = new ArrayCollection(); private function handleFault(fault:Object):void { Alert.show(ObjectUtil.toString(fault)); } private function loadData(lr:Object):void { apex.query("Select Name, Phone, Type From Account", new AsyncResponder( function(qr:QueryResult):void { if (qr.size > 0) { accountList = qr.records; } }, handleFault) ); } ]]> </mx:Script> <mx:DataGrid dataProvider="{accountList}" left="10" right="10" top="10" bottom="10"> <mx:columns> <mx:DataGridColumn dataField="Name"/> <mx:DataGridColumn dataField="Phone"/> <mx:DataGridColumn dataField="Type"/> </mx:columns> </mx:DataGrid> </mx:Application>

 

 

I have removed the login function parameter, but the code should work fine with it also..

 

 

The code is working fine for me after these changes...

This was selected as the best answer
patelankurbpatelankurb

Thanks Arun for your suggestion. It seems $API.Session_ID is not transferring correct sessionId to Flex, which is bug. So your workaround to get session using UserInfo is working fine in Firefox, IE, and Safari too. But in safari it takes lot of time to load data.

 

 

On VF page I have removed standardController and extensions, and used only controller attribute and working fine for me.

 

Thanks,

Ankur

jamis0njamis0n

Is there a way to use this workaround without creating a new controller extension class?


I have a free developer account and I cannot create new custom classes.

 

Any help is appreciated!

 

Thanks!