Adobe Salesforce 问题将 ID 更改为名称 [英] Adobe Salesforce problem changing Id to Name

查看:31
本文介绍了Adobe Salesforce 问题将 ID 更改为名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am having a problem converting for example the AccountId field in Contacts to the Account Name from the Account Object.

我尝试了以下查询:

从联系人中选择姓名、帐户名称

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

But when I look at the Console when I debug the application I see that this has been converted to

从 Entity_Contact 中选择称呼、名字、姓氏、AccountId

select Salutation, FirstName, LastName, AccountId from Entity_Contact

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

So the result is that just the Account Id is shown, which I could have got from the Contact record in the first place.

有什么方法可以获取帐户名称,以便我可以在 DataGrid 中显示它.

Is there any way to get the Account Name so that I can display it in a DataGrid.

谢谢

罗伊

推荐答案

您的语法是正确的.Flashbuilder for Force.com 的 DesktopWrapper 类直接与本地数据存储交互,后者又处理与 Force.com 的同步.不幸的是,在当前版本中,不支持与本地存储之间的关系查询.这就是您看到查询扁平化"的原因.

Your syntax is correct. The DesktopWrapper class of Flashbuilder for Force.com interacts with the local data store directly, which in turns handles the syncing to Force.com. Unfortunately, in the current release, relationship queries are not supported to and from the local store. That's why you see your query "flattened".

注意控制台窗口中记录的是从 SOQL 到 SQL 的转换.SQLl 是针对本地存储执行的内容.

Notice in the console window that what is logged is the translation from SOQL to SQL. The SQLl is what is executed against the local store.

如果你需要离线数据,那么你需要通过 app.wrapper 类执行两个查询并关联,或者在客户端加入数据.由于 ActionScript 是动态的,您只需将帐户数据附加到具有相应帐户 ID 的联系人数据即可.

If you need to have the data offline, then you will need execute two queries via the app.wrapper class and correlate, or join the data on the client. Since ActionScript is dynamic, you can just attach the Account data to the contact data with the corresponding Account 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 对象的原始查询.

If you don't need to have offline capability, you can use your original query with the app.connection object.

这篇关于Adobe Salesforce 问题将 ID 更改为名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆