Adobe Salesforce问题将Id更改为Name

时间:2010-10-11 13:04:45

标签: flex flash air adobe salesforce

我遇到问题,例如将联系人中的AccountId字段转换为帐户对象中的帐户名称。

我尝试了以下查询:

  

从联系人

中选择姓名,帐户名称

但是当我在调试应用程序时查看控制台时,我发现它已转换为

  

从Entity_Contact选择Salutation,FirstName,LastName, AccountId

因此,结果是只显示了帐户ID,我首先可以从联系人记录中获得。

有没有办法获取帐户名称,以便我可以在DataGrid中显示它。

由于

罗伊

1 个答案:

答案 0 :(得分: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对象一起使用。