Visualforce RemoteObjectModels 使用 "OR" 进行查询过滤

Visualforce RemoteObjectModels Query filtering using "OR"

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

中显示的示例文档中的以下代码片段

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

在我的代码片段中,我有一个 '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 个以上的过滤器,我该如何实现? 'OR' 在远程对象中的用法是否正确?有没有人遇到过这个问题。如果可以,请给我一些指示。

提前致谢。

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

首先,这是一个(模糊的)已知限制,您不能为 ANDOR 查询设置超过 2 个谓词 - 文档 here

但是,您似乎发现了另一个错误,标准字段 (Name, 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 列表。

祝你好运!