2010-10-11 32 views
1

我遇到問題,例如將聯繫人中的AccountId字段轉換爲帳戶對象中的帳戶名稱。從聯繫Adob​​e Salesforce問題將ID更改爲名稱

選擇名稱,Account.Name但是,當我看到控制檯時,我調試應用程序,我發現這樣的:

我曾嘗試下面的查詢已轉換爲

select請稱呼,名字,姓氏,AccountId from Entity_Contact

所以結果是隻顯示帳戶ID,我可以從聯繫人記錄中得到第一個地方。

是否有任何方法獲取帳戶名稱,以便我可以在DataGrid中顯示它。

感謝

羅伊

+0

您是否使用Flash Builder for Force.com?如果是這樣,那麼我認爲它可能不支持這些後代查詢。 – 2010-10-11 14:28:23

+0

是的,我是,hwat其他方式有創建一個空氣應用程序,使我可以使用這種類型的查詢,或有一個workarround? – Roy 2010-10-12 06:58:57

回答

3

你的語法是正確的。 Force.com的Flashbuilder的DesktopWrapper類直接與本地數據存儲進行交互,然後輪流處理與Force.com的同步。不幸的是,在當前版本中,關係查詢不支持本地商店和從本地商店支持。這就是爲什麼你看到你的查詢「扁平化」。

注意在控制檯窗口中記錄的是從SOQL到SQL的轉換。 SQLl是針對本地商店執行的內容。

如果您需要讓數據脫機,那麼您需要通過app.wrapper類執行兩個查詢,並關聯或在客戶端上加入數據。由於ActionScript是動態的,您只需將帳戶數據附加到具有相應帳戶ID的聯繫人數據即可。

這裏是什麼,可能看起來像一個刺:

  [Bindable] 
     protected var myData:ArrayCollection = new ArrayCollection(); 

     protected function loginCompleteHandler(event : LoginResultEvent) : void { 
      CursorManager.removeBusyCursor(); 
      // When the login is complete the main state should be shown. 
      currentState = "main"; 
      //Execute the contact Query 
      app.wrapper.query("Select Id, FirstName, LastName, AccountId From Contact", 
       new AsyncResponder(contactQueryHandler, faultHandler, myData) 
      ); 
     } 

     // This function will iterate over the results creating a string value for the 
     // "in" clause of the embedded Account query. It also creates a field on the 
     // Contact dynamic entity so that our data binding works after initially setting 
     // the data provider variable. 
     protected function contactQueryHandler(qr:ArrayCollection, token:Object):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 
       myData.addItem(contact); // Add contact to grid data data provider 
      } 
      acctIdss = acctIdss.substr(0, acctIdss.length - 1); 
      // Query for the accounts based on the account ids found in the contact list 
      app.wrapper.query("Select Id, Name From Account Where Id in (" + acctIdss + ")", 
       new AsyncResponder(accountQueryHandler, faultHandler)); 
     } 

     // This function simply iterates over the results and then iterates over the data grid 
     // data provider to set the Account name for the correct contact. Since data binding has 
     // already occurred, the account name will be automatically displayed in the grid. 
     protected function accountQueryHandler(accounts:ArrayCollection, token:Object):void { 
      for each (var account:DynamicEntity in accounts) { 
       for each(var contact:DynamicEntity in myData) { 
        if (contact.AccountId == account.Id) { 
         contact.AccountName = account.Name; 
        } 
       }            
      } 
     } 


    <s:Group includeIn="main" 
     enabled="{!app.loginPending}" 
     width="100%" 
     height="100%"> 
    <s:layout> 
     <s:BasicLayout/> 
    </s:layout> 
    <s:VGroup paddingTop="10" 
       paddingLeft="10" 
       paddingRight="10" 
       paddingBottom="10" width="100%" height="100%"> 
     <mx:DataGrid id="dGrid" dataProvider="{myData}" width="100%" height="100%"> 
     </mx:DataGrid> 
    </s:VGroup> 
    <flexforforce:StatusBar left="0" 
          bottom="0"/> 
</s:Group> 

如果你不需要具備離線功能,你可以用你的原始查詢與app.connection對象。