Visualforce Remote Object Query 'where-like' Criteria Syntax Improvement - Ideas - Salesforce Trailblazer Community

All Ideas

Idea Details

Post an Idea
20  Points
Open
Idea has been posted. Give it an upvote or downvote.

Visualforce Remote Object Query 'where-like' Criteria Syntax Improvement

Visualforce & Aura

1. Where like a list of string:

It is possible to query a 'where like' list of string in Apex soql:
Set<String> LikeNameSet= new set<String>();
LikeNameSet.add('%test1%');
LikeNameSet.add('%test2%');
List <Contact> conList =  [select id, email from Contact where email like:LikeNameSet];

However naively trying the same approach using Remote Object results in error on client
<apex:remoteObjects >
    <apex:remoteObjectModel name="Contact" jsShorthand="conRemoteObj" fields="Id, Email"/>       
</apex:remoteObjects> 
<script> 
    ...
    var conObj = new SObjectModel.conRemoteObj();
    let likeEmailList = ['%test1','%test2%'];
    let criteria = {
        where: {     
            Email: {like: likeEmailList }     
        } 
    };                               

    conObj.retrieve(criteria,callback);   

    function callback(){    
        //do something here...    
    }      
    ...    
</script>
Error on client:
Invalid criteria specified for
> retrieval. ValidationError [code=11, message=Data does not match any
> schemas from &quot;oneOf&quot;, path=/where, schemaKey=null]


2. 'where-or' to the same field multiple times:

The following criteria leads to the error as above:
let criteria = {
	where: {
		Id: {in: ids},
		or:{
			Email: {like: '%test1%'},
			Email: {like: '%test2%'}                            
		}

	} 
};
Accoring to the following post https://salesforce.stackexchange.com/questions/45173/ors-and-ands-in-the-retrieve-function-of-visualforce-remote-objects, It has to be rewritten into a nested syntax
let criteria = {
	where: {
		Id: {in: ids},
		or:{
			Email: {like: '%test1%'},
			or:{
				and:{
					firstname: {eq: 'dummy'},
					lastname: {eq: 'dummy'},
				}
				Email: {like: '%test2%'} 
			}			                           
		}
	} 
};

Most important, documentation about query criteria is misleading and primitive.  https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_remote_objects_using_retrieve_query_object.htm
{ 
where: 
    { 
    or: 
        {
        FirstName: { like: "M%" }, 
        Phone: { like: '(415)%' }
        }
    }
}
It says nothing about refering the same field, which leads to error.

Visualforce Remote Object is a really awesome standard for modern coding, therefore improvement would be great!



 
 

Merge Idea · Flag

  • Upvotes
  • Downvotes

Ideas

Apps

from AppExchange

Questions

Help us to keep IdeaExchange clean by pointing out overlapping ideas. We'll investigate your suggestion and merge the ideas if it makes sense.



 

 

Thanks for your merge suggestion. We will review it shortly and merge the ideas if applicable.

Salesforce takes abuse situations very seriously. Examples of abuse include but are not limited to posting of offensive language or fraudulent statements. To help us process your request as quickly as possible, please fill out the form below describing the situation. For privacy and security reasons, the final outcome of an abuse case may not be revealed to the person who reported it.


 

Thank you for your feedback. We take abuse seriously and will investigate this issue and take appropriate action.