开发者

Adobe Flex Salesforce problem converting account ids to account name

I am using Adobe Air to get data from SalesForce, and present it in a datagrid.

I am using a query to get the data, and then put it into an arraycollection that is bound to the datagrid, this works correctly and the data is displayed.

The problem is that I want to convert the Account Id in the Event to show the account Name. To do this I am using the following code:-

   _serviceWrapper.query( "Select * From Event order by StartDateTime asc", new mx.rpc.Responder( eventQueryHandler, faultHandler ))}

   protected function eventQueryHandler(qr:ArrayCollection):void {
     var acctIdss:String = ""; 
    for each(var contact:DynamicEntity in qr) { 
     if (contact.AccountId != null && acctIdss.indexOf(contact.AccountId) == -1) { 
      acctIdss += "'" + contact.AccountId + "',"; 
     } 
     //contact.AccountName = "";  // Add field to contact for account name 
     TempGridProvider.addItem(contact);   // Add contact to temp grid data data provider 
     //TempGridProvid开发者_Python百科er.contact.AccountName = "";
    } 
    acctIdss = acctIdss.substr(0, acctIdss.length - 1);
    // Query for the accounts based on the account ids found in the contact list 
    _serviceWrapper.query("Select Id, Name, BillingCity From Account Where Id in (" + acctIdss + ")",  
     new SfdcAsyncResponder(Event2QueryHandler, faultHandler));
   } 
   protected function Event2QueryHandler(accounts:ArrayCollection):void { 
    for each (var account:DynamicEntity in accounts) { 
     for each(var contact:DynamicEntity in TempGridProvider) { 
      if (contact.AccountId == account.Id) { 
       contact.AccountName = account.Name + " - " + account.BillingCity;
      } 
     }                                             
    }
    onQueryResult(TempGridProvider);

   private function onQueryResult( rows : ArrayCollection ) : void {
    // release previous query results
    _serviceWrapper.releaseQueryResults( _gridDataProvider );

    // populate datagrid
    _gridDataProvider = rows;

    // show message in status bar
    var status : F3Message = new F3Message( F3Message.STATUS_INFO, "Query came back with " + ( _gridDataProvider == null ? 0 : _gridDataProvider.length ) + " " + _selectedEntity + "s" );
    showStatus( status );
    TempGridProvider = new ArrayCollection();;
   }

This works and displays the Account Name, the problem is that when I use this script and then Sync Changes to SalesForce all the records that have been displayed are identified as needing to be syncronised even if they have only been displayed.

If I skip the function eventQueryHandler, and link my query to the OnQueryResult function then there is no problem, but only the Account Id can be displayed.

How can I stop Air marking these records as having changed, or is there a better way to achieve this??

Thanks in advance, any help is greatly appreciated.

Roy


I think you need to not manipulate the underlying object. There are two options for getting the data to render in a DataGrid.

Option 1 - Create another non-managed ValueObject that holds the values you need to display in the DataGrid. Copy the values when you receive them into the new ValueObject.

Option 2 - Use a labelFunction on the DataGridColumn to fetch the data externally when each cell in a given column is rendered.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜