Trusted Contributor
gtuerk
Posts: 160
Accepted Solution
as3Salesforce.swc - Flex Toolkit no longer working?

I'm befuddled and puzzled.  I just got the Google Maps API for Flex to embed properly in SF and now I am trying to get a data grid to fill with SF data in the same SWF.  I've gotten data out of Salesforce in the past using the as3salesforce.swc library but it doesn't seem to work anymore.  I've been following threads about the appropriate server_url (which I've now replaced with v15 to no avail).  Anybody else noticing problems with the toolkit?

 

<apex:page standardController="Location__c">
<apex:form >
<apex:pageBlock title="Flex implementation">
<apex:flash id="flexSOs" src="{!$Resource.SFFlex}" height="100%" width="100%"
flashvars="session_id={!$Api.Session_ID}&server_url={!$Api.Partner_Server_URL_150}"/>
</apex:pageBlock>
</apex:form>
</apex:page>

 Here's the mxml code:

 

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
xmlns:salesforce="http://www.salesforce.com/"
creationComplete="login(event)"
viewSourceURL="srcview/index.html">
    <salesforce:Connection id="connection"/>
   
    <mx:Script>
    <![CDATA[
    import com.salesforce.objects.SObject;
    import com.salesforce.results.QueryResult;
    import com.salesforce.AsyncResponder;
    import com.salesforce.objects.LoginRequest;
    import mx.core.IUIComponent;
    import mx.managers.DragManager;
    import mx.events.DragEvent;
    import mx.collections.ArrayCollection;
    import flash.external.ExternalInterface;
   
    [Bindable]
    public var selectedItem:Object;
    [Bindable]
    public var selectedSOs:ArrayCollection = new ArrayCollection();;

    private function login(event:Event):void {
                var lr:LoginRequest = new LoginRequest();
                lr.server_url = parameters.server_url;
                lr.session_id = parameters.session_id;
                lr.callback = new AsyncResponder(getCandidateSOs);
                connection.login(lr);
            }
   
    private function getCandidateSOs(o:Object=null):void{
        connection.query("Select Id, A_Loc__c from Service_Order__c"
        , new AsyncResponder(
        function (qr:QueryResult):void {
            candidateSOs.dataProvider = qr.records;
        }));

    }
    ]]>
    </mx:Script>

<mx:Form id="frmPrintSO"
            width="100%" height="75%"
            borderStyle="solid" borderColor="#D4D4D4"
            dropShadowEnabled="true" dropShadowColor="#B3B3B3"
            shadowDirection="right" shadowDistance="10">
    <mx:FormHeading label="Signature SOs"     />
    <mx:HBox>
        <mx:VBox>
            <mx:Label text="Candidate SOs"/>
            <mx:DataGrid id="candidateSOs"
                allowMultipleSelection="true"
                dragEnabled="true"
                dropEnabled="true"
                dragMoveEnabled="true">
                <mx:columns>
                    <mx:DataGridColumn dataField="Name"/>
                    <mx:DataGridColumn dataField="A_Loc__c"/>
                </mx:columns>   
            </mx:DataGrid>
        </mx:VBox>
    </mx:HBox>
</mx:Form>
</mx:Application>

Regular Contributor
wintamute
Posts: 39
Re: as3Salesforce.swc - Flex Toolkit no longer working?
[ Edited ]

If you get errors about invalid sessions, I noticed that the {!$Api.Session_ID} approach isn't always working. Why, I have no idea, but I got it working by using a Controllerextension which uses Apex to get the current session ID instead.

 

 

public class GetSessionControllerExtension {

public GetSessionControllerExtension(ApexPages.StandardController stdController) {

}

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

 

<apex:page standardController="Location__c" extensions="GetSessionControllerExtension">
<apex:form >
<apex:pageBlock title="Flex implementation">
<apex:flash id="flexSOs" src="{!$Resource.SFFlex}" height="100%" width="100%"
flashvars="session_id={!MySessionId}&server_url={!$Api.Partner_Server_URL_150}"/>
</apex:pageBlock>
</apex:form>
</apex:page>

 

 

Message Edited by wintamute on 04-28-2009 11:05 AM
Trusted Contributor
gtuerk
Posts: 160
Re: as3Salesforce.swc - Flex Toolkit no longer working?
thanks Wintamute.  this worked for me and I am grateful.  cheers
Super Contributor
Ron Hess
Posts: 2,538
Re: as3Salesforce.swc - Flex Toolkit no longer working?

That is very strange, i'm glad you got it working. 

Those session ID's should be the same, unless i'm missunderstanding something.

Ron Hess
Salesforce Developer Evangelist
Check out the developer documentation | Got an idea? | Vote for this Idea!
Regular Contributor
wintamute
Posts: 39
Re: as3Salesforce.swc - Flex Toolkit no longer working?
[ Edited ]

Yes, that was my understanding also. And interestingly enough, sometimes it works. Sometimes it doesn't. I tried it with several different Orgs, Enterprise and Developer, with namespaces and without and couldn't find a pattern to track it down reliably.

It might depend on the cluster the org is residing on, but that's just a guess.

 

Maybe someone from the SFDC Dev team can look into it?

Message Edited by wintamute on 04-29-2009 10:44 AM
Regular Visitor
ronak
Posts: 2
Re: as3Salesforce.swc - Flex Toolkit no longer working?
I also fixed my login problems with this extension. Can you explain why the session ID's weren't the same?
Regular Contributor
Posts: 42
Re: as3Salesforce.swc - Flex Toolkit no longer working?
Same problem here. $Api.Session_ID returns a different value that the session id returned by wintamute's workaround. Thanks very much for the wa, wintamute! (my wall thanks you and so does my head)