1

You can copy and paste my code easily into your dev console to debug this. I'm trying to get a list of users from a remote object query. After typing a value in the input box, click outside the box and you get this error.

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

I'm pretty sure I followed the docs correctly.

<apex:page >

    <!-- Remote Objects definition to set accessible sObjects and fields -->
    <apex:remoteObjects >

        <apex:remoteObjectModel name="User" fields="Id, FirstName, LastName, Email"/>

    </apex:remoteObjects>  

    <input type="text" name="txt" onchange="fetchUsers(this.value)" />


    <h1>List of users</h1>

    <ul id="userList">
    </ul>

        <!-- JavaScript to make Remote Objects calls -->
    <script>
        function fetchUsers(string){
            // Create a new Remote Object
            var u = new SObjectModel.User();

            // Use the Remote Object to query for 10 user records


            var criteria = { where: {
                FirstName: {like: string.split(' ')[0]},
                LastName:  {like: string.split(' ')[1]}
            },
            orderby: [ {LastName: 'ASC'}, {FirstName: 'ASC'} ],
            limit: 10 
            };

            console.log(criteria);

            u.retrieve(criteria, function(error, results, event){
                if(error) {
                    alert(error.message);
                }
                else{
                    var ul = document.getElementById("userList");
                    results.forEach(function(record) {
                        var uText = record.get("Id");
                        uText += " -- ";
                        uText += record.get("FirstName");
                        uText += " -- ";
                        uText += record.get("LastName");
                        uText += " -- ";
                        uText += record.get("Email");

                        var li = document.createElement("li");
                        li.appendChild(document.createTextNode(uText));
                        ul.appendChild(li);
                    });
                };

            });
        };
    </script>

</apex:page>
2

I did some testing with your model and my observation is that the query does not seem to like it (ha) when you use a like clause which does not include a wildcard. I tried with just FirstName, just LastName, and with both, and no matter what, any time I included a like clause which did not contain a wildcard, it blew up with the same error you described. This leads me to conclude:

You cannot retrieve records with Remote Objects using a like clause that does not contain a wildcard character (% or _).

I don't have a reference for that, it's just my observation.

The following worked for me just fine. I added a loop to clear out previous results and tightened things up marginally.

<apex:page >
    <apex:remoteObjects >
        <apex:remoteObjectModel name="User" fields="Id, FirstName, LastName, Email"/>
    </apex:remoteObjects>  
    <input type="text" name="txt" id="user_search" />
    <h1>List of users</h1>
    <ul id="userList"></ul>
    <script>
    document.getElementById("user_search").addEventListener("change", function () {
        var u = new SObjectModel.User(),
            elements = this.value.split(" "),
            first = (elements[0] || "") + "%",
            last = (elements[1] || "") + "%",
            criteria = {
                where: {
                    FirstName: {like: first},
                    LastName:  {like: last}
                },
                orderby: [ {LastName: "ASC"}, {FirstName: "ASC"} ],
                limit: 10 
            };
        u.retrieve(criteria, function(error, results, event){
            if(error) {
                alert(error.message);
            }
            else{
                console.debug(results);
                var ul = document.getElementById("userList");
                while (ul.firstChild) { ul.removeChild(ul.firstChild); }
                results.forEach(function(record) {
                    var uText = record.get("Id");
                    uText += " -- ";
                    uText += record.get("FirstName");
                    uText += " -- ";
                    uText += record.get("LastName");
                    uText += " -- ";
                    uText += record.get("Email");

                    var li = document.createElement("li");
                    li.appendChild(document.createTextNode(uText));
                    ul.appendChild(li);
                });
            };

        });
    });
    </script>
</apex:page>
|improve this answer|||||
  • Wow thanks. I wish the docs said that. I guess it's implied from the docs saying " As with SOQL, use “%” as a wildcard character." – Tyler Zika Nov 3 '16 at 0:07
  • 1
    But in SOQL, the wildcard is not required. Ah well. – Adrian Larson Nov 3 '16 at 0:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.