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
WardsterWardster 

Flex Control works standalone but not deployed on Salesforce.

I have created a Flex chart which seems to work fine in standalone mode with the Flex Builder but I'm having difficulty getting it to work when I deploy it to Salesforce.  I suspect that the queries are breaking since I'm see Array Out of Bounds errors.  Is there some login or security setting in Salesforce I need to adjust to get the query API functional?  My code is pasted below:
Code:
<—xml version="1.0" encoding="utf-8"–>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" 
 xmlns:salesforce="com.salesforce.*" 
 layout="horizontal"
 applicationComplete="login();" backgroundGradientAlphas="[1.0]" backgroundColor="#F8F8F8" backgroundImage="">

      
     <mx:Script>
        <![CDATA[
        
            import mx.collections.ArrayCollection;
        
            import com.salesforce.results.*;
            import com.salesforce.events.*; 
            import com.salesforce.objects.*;
            import com.salesforce.*;
            
            [Bindable]
            private var revenueExpectedArray:ArrayCollection = new ArrayCollection();
            [Bindable]
            private var revenueReportedArray:ArrayCollection = new ArrayCollection();
            [Bindable]
            private var buildingId:String = new String();

            
            
            private function login(): void {
             initVariables();
             apex.login(  new LoginRequest({
           server_url : this.parameters.server_url,
           session_id : this.parameters.session_id,
           // put your own info here to test standalone
           username : 'xxx@xxxx.com',
           password : 'mypassword',
           callback : new AsyncResponder(render)
                })
                );

             
            }
            
            // initializes the building id variable
            private function initVariables():void {
             buildingId = Application.application.parameters.buildingId;
             // buildingId = "a0G80000000xF4xEAE";
            }
            
            private function render(result:Object):void {
             var numberOfRevenueExpectedRecords:int = 6;
       apex.query("Select Date__c, Month_Year__c, Revenue_Expected__c From Revenue_Entry__c WHERE Building__c = '" + buildingId + "' AND Revenue_Expected__c != null ORDER BY Date__c DESC LIMIT " + numberOfRevenueExpectedRecords,
       new AsyncResponder(
        function (qr:QueryResult):void {
         if(numberOfRevenueExpectedRecords < qr.size){
          numberOfRevenueExpectedRecords = qr.size;
         }
         // we've gotten the last six records now we need to iterate backwards through the results
                  for (var j:int=numberOfRevenueExpectedRecords - 1;j >= 0;j--  ) {
                      revenueExpectedArray.addItem( {Month:qr.records[j].Month_Year__c, Value:qr.records[j].Revenue_Expected__c/1000000});
                  }
              }, function (fault:Object):void {}
        ));
        var numberOfRevenueReportedRecords:int = 6;
        apex.query("Select Date__c, Month_Year__c, Revenue_Reported__c From Revenue_Entry__c WHERE Building__c = '" + buildingId + "' AND Revenue_Reported__c != null ORDER BY Date__c DESC LIMIT " + numberOfRevenueReportedRecords,
                 new AsyncResponder(
                    function (qr:QueryResult):void {
                     if(numberOfRevenueReportedRecords < qr.size){
                            numberOfRevenueReportedRecords = qr.size;
                        }
                     // we've gotten the last six records now we need to iterate backwards through the results
                        for (var j:int=numberOfRevenueReportedRecords - 1; j >= 0;j--  ) {
                            revenueReportedArray.addItem( {Month:qr.records[j].Month_Year__c, Value:qr.records[j].Revenue_Reported__c/1000000});
                        }
                    }, function (fault:Object):void {}
                 ));
            }


            
        ]]>
        
        
    </mx:Script>
    
    <salesforce:Connection id="apex" />

    
    <mx:Stroke id = "s1" color="blue" weight="2"/>
    <mx:Stroke id = "s2" color="red" weight="2"/>
    
    <mx:SeriesInterpolate id="interpolateIn" duration="1000"/>
    
    
     <mx:Panel title="Revenue Entries" layout="horizontal" color="0xffffff" borderAlpha="1.0" width="963" height="429"
         paddingTop="10" paddingRight="5" paddingBottom="10" paddingLeft="5" horizontalAlign="center" borderColor="#00335B">
   <mx:LineChart id="revenue_entry_chart" width="710" dataProvider="{revenueReportedArray}" showDataTips="true" fontFamily="Arial" height="350" color="#000000">
 
       <mx:horizontalAxis>
                    <mx:CategoryAxis  id="x_axis" categoryField="Month"/>
                </mx:horizontalAxis>
                <mx:horizontalAxisRenderers>
                    <mx:AxisRenderer axis="{x_axis}" showLine="true" showLabels="true"/>
                </mx:horizontalAxisRenderers>
                
                <mx:verticalAxis>
                 <mx:LinearAxis id="y_axis" title="Revenue in Millions ($)" />
               </mx:verticalAxis>
                <mx:verticalAxisRenderers>
                    <mx:AxisRenderer axis="{y_axis}" showLine="false" showLabels="true"/>
                </mx:verticalAxisRenderers>
                                    
    <mx:series>
     <mx:LineSeries displayName="Revenue" yField="Value" lineStroke="{s2}" showDataEffect="{interpolateIn}"/>
    </mx:series>
   </mx:LineChart>
   
   <mx:VBox color="0x323232" width="30%" borderColor="0x9096A1" borderStyle="solid" height="352"
             paddingLeft="5" paddingRight="0" paddingTop="5">
             
             <mx:Text color="#000000" width="100%" text="Choose a data series:"/>
             
             <mx:RadioButton groupName="stocks" label="Revenue Reported"
                 selected="true" click="revenue_entry_chart.dataProvider=revenueReportedArray;"/>
             <mx:RadioButton groupName="stocks" label="Revenue Expected"
                 click="revenue_entry_chart.dataProvider=revenueExpectedArray;"/>
            </mx:VBox>
   
  </mx:Panel>
 
</mx:Application>

 


 
WardsterWardster
After a little more research I've figured out that my custom object Id =, in this a case a Building__c.Id isn't get populated through the S-Control, so naturally my query is coming up empty.
WardsterWardster
Well, I thought I was on the right track when I figured out the buildingId (My Custom Object record id) was coming up null but there must be some other issue as well.  I pulled the id into a flashvar param in my own wrapper and the chart/flex works fine but as soon as I load it into Salesforce it just freezes.  The chart loads but it doesn't do anything.  I'm baffled.  Here is the code for my apex:flash control.  I can see in Firebug all the params are getting passed in.  They at least look correct.

<apex:flash width="1122" height="500" flashvars="session_id={!$Api.Session_ID}&server_url={!$Api.Partner_Server_URL_90}&buildingId={!building.Id}" src="{!$Resource.revenue_entry_chart}" play="true"/>


Any help would really be appreciated.

Thanks