function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
VT878VT878 

Remote Object and WHERE condition

Hi, I have a problem with Remote Object.

 If I use one logical operator is all ok. The problems is present when I use more logical operator (for example: OR[AND(condition1, condition2), AND(condition3, condition4)]
 
 The error message is: "Error: Invalid criteria specified for retrieval. ValidationError [code=11, message=Data does not match any schemas from "oneOf", path=/where, schemaKey=null]" 

My code is here:
var contatti = new SObjectModel.Contact();
var criteria = {};
var results = [];									
var criteria = {};
var firstString = 'test1';
var secondString = 'test2';



criteria.where  = { 
    or: 
        {

            and:
                {
					FirstName: {like: firstString  + '%'},
					LastName: {like: secondString + '%'}
                 },

            and:
                {
                    FirstName: {like: secondString + '%'},
                    LastName: {like: firstString + '%'}
                 }
         }

 

contatti.retrieve(
                    criteria,
                    function(err, records, event) {
                        if(err) console.log('errore:'+err);
                        if(!err) {
                            for (var i = 0; i < records.length; i++) {
                                results.push({
                                    label: records[i].get('LastName') + ' ' + records[i].get('FirstName'),
                                    id: records[i].get('Id')
                                });
                            }
                            callback(results);
                        }
                    }
                );
Thanks!!!
 
NagendraNagendra (Salesforce Developers) 
Hi VT878,

First and foremost sincerely regret for the delayed reply.

Description:When using Visual Force Remote Objects, if a Query is formulated with "AND" clause, it takes only 2 predicates. 
If more than 2 predicates are specified , such as in the code below, the following error is thrown: 
var Qry = { 
	where: 
	{ 
		and: 
		{ 
			accountId: { eq: '{!Opportunity.AccountId}'}, 
			IsClosed: {eq: false}, 
			NextStep: {eq:'review'}
		} 
	} 
};
Error Message:"Error: Invalid criteria specified for retrieval. ValidationError [code=11, message=Data does not match any schemas from "oneOf", path=/where, schemaKey=null]" 

Resolution:This is working as expected since "AND" ( and "OR") logical operator must have 2 objectives. 

As a workaround for "AND" to work with multiple filters ,  syntax mentioned in the following code can be used: 
var Qry = { 
	where: { 
		accountId: { eq: '{!Opportunity.AccountId}'}, 
		NextStep: {eq:'review'}, 
		StageName: {eq:'Prospecting'}, 
		LeadSource: {eq:'Web'}, 
		IsClosed: {eq: false} 
	} 
};
Hope this helps.

Mark this as solved if it's resolved.

Best Regards,
Nagendra.P