【问题标题】:Visualforce RemoteObjectModels Query filtering using "OR"Visualforce RemoteObjectModels 使用“或”进行查询过滤
【发布时间】:2015-11-26 01:35:04
【问题描述】:

我在 Salesforce.com 的 visualforce 页面中使用。出于演示目的,我使用了

中显示的示例文档中的以下代码 sn-p

http://docs.releasenotes.salesforce.com/en-us/spring14/release-notes/rn_vf_remote_objects.htm

在我的代码 sn-p 中,我有一个“Where”子句,我试图在其中使用 3 个字段进行过滤。我的要求是记录必须符合条件 A 或条件 B 或条件 C。

代码示例

<apex:page >
    
    <!-- Remote Objects definition to set accessible sObjects and fields -->
    <apex:remoteObjects >
        <apex:remoteObjectModel name="Group_Donor__c" jsShorthand="Groupdonor" 
            fields="Name,Id">
            <apex:remoteObjectField name="State__c" jsShorthand="State"/>
            <apex:remoteObjectField name="Org_Phone__c" jsShorthand="Phone"/>
            <apex:remoteObjectField name="Billing_Type__c" jsShorthand="billingtype"/>
        </apex:remoteObjectModel>
    </apex:remoteObjects>

    <!-- JavaScript to make Remote Objects calls -->
    <script>
        var fetchWarehouses = function(){
            // Create a new Remote Object
            var wh = new SObjectModel.Groupdonor();
            
            // Use the Remote Object to query for 10 warehouse records
            wh.retrieve({
                where: { 
                          or: {
                                Name : {like:"%Helloworld%"}, // Error
                                State: {like:"%chennai%"},
                                //Phone: {like:"%098765432344%"}, 
                                billingtype: {like:"%Credit Card%"}
                              } 
                          }, 
                limit: 10 , 
            }, function(err, records, event){
                if(err) {
                    alert(err.message);
                }
                else {
                    var ul = document.getElementById("warehousesList");
                    records.forEach(function(record) {
                        // Build the text for a warehouse line item
                        var whText = record.get("Name");
                        whText += " -- ";
                        whText += record.get("Phone");
                        whText += " -- ";
                        whText += record.get("billingtype"); 
                        
                        // Add the line item to the warehouses list
                        var li = document.createElement("li");
                        li.appendChild(document.createTextNode(whText));
                        ul.appendChild(li);
                    });
                }
            });
        };
    </script>

    <h1>Retrieve Group Donors via Remote Objects</h1>

    <p>Warehouses:</p>

    <ul id="warehousesList">
    </ul>
    <button onclick="fetchWarehouses()">Retrieve Group Donors</button>

</apex:page>

当我执行此代码时,我收到以下错误。

错误信息:

Invalid criteria specified for retreival. ValidationError [code=11, message=Data does not match any schemas from &quot;oneOf&quot; path=/where, schemaKey=null]

此问题仅在以下情况下发生。

  1. 当我在 OR 条件中使用标准字段(如名称)时。 (甚至 2 或 1 个过滤器)
  2. 当我在 OR 条件中使用超过 3 个自定义字段时(超过 2 个查询过滤器)

但是,当我只使用 RemoteObjectModel 中提到的任何 2 个自定义字段作为过滤器时,我得到了预期的结果。

请让我知道我在这里缺少什么。如果我在或条件下使用了超过 2 个过滤器,我该如何实现?在远程对象中正确使用“或”吗?有没有人遇到过这个问题。如果是这样,请给我一些指示。

提前致谢。

【问题讨论】:

    标签: salesforce visualforce apex force.com remoteobject


    【解决方案1】:

    我一直在寻找,有一些坏消息和一些好消息。

    首先,这是一个(模糊的)已知限制,对于 ANDOR 查询,您不能有超过 2 个谓词 - Docs here

    但是,您似乎发现了另一个错误,即标准字段(名称、ID)在与自定义字段一起使用时似乎不起作用。我的解决方法是重新定义所有字段,甚至是这样的标准字段:

    <apex:remoteObjectModel name="Group_Donor__c" jsShorthand="GroupDonor">
        <apex:remoteObjectField name="Name" jsShorthand="NameJS"/>
        <apex:remoteObjectField name="State__c" jsShorthand="State"/>
        <apex:remoteObjectField name="Org_Phone__c" jsShorthand="Phone"/>
    <!--.... etc-->
    

    至少你可以通过这种方式查询标准字段。

    作为最终解决方法,您可能必须检索两个记录列表并使用 JavaScript 创建您的最终 OR 列表。

    祝你好运!

    【讨论】:

    • 看来我们必须忍受这个!感谢您的宝贵时间。
    • 是的,我也有点失望地发现了这个限制!我想有一些解决方法,但仍然不是很好。我已经不得不实现一个递归记录检索系统来绕过 100 条记录的限制,所以这只会变得更糟。希望他们会在某个时候更新 API。
    猜你喜欢
    • 2012-08-22
    • 2017-04-13
    • 1970-01-01
    • 2015-03-12
    • 2021-06-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多