2

Is it possible to query a 'where like' list of string with remote object? That is possible 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 I tried the analogy in vain using remote object:

<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> 

the code above results in javascript alert error like:

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

I cannot find anything about this where-like syntax in documentation:

https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_remote_objects_using_retrieve_query_object.htm

thanks in advance

0

I think you can add 'in' after the 'like' condition, try like this

instead of

   where: {     
                Email: {like: likeEmailList }     
          } 

try like this

   where: {     
                    Email: {like:{ in: likeEmailList} }     
              } 

if you are still facing any issue, the below method should work:

where: 
    { 
    or: 
        {
        Email: { like: "%test1" }, 
        Email: { like: '%test2%' }
        }
    }

Please check the below link to get more details of VF remote objects: https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_remote_objects_using_retrieve_query_object.htm

|improve this answer|||||
  • thy for your suggestions. Sadly none of them works. Especially the second one, the official documentation is very misleading. Since Javascript does not understand the same field applied multiple times in or:{...}. The code above will lead to the same error as I posted. Check here salesforce.stackexchange.com/questions/45173/… – Leon Sep 4 '19 at 10:23
  • Okay, Have u tried like this : where: { or: { Email: { like: "%test1" }, or:{ Email: { like: '%test2%' } }, }, } Please let me know if this works – Nishad kallingal Sep 4 '19 at 11:55
0

@Nishad, the following nested syntax works for me according to https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_remote_objects_using_retrieve_query_object.htm.

let criteria = {
    where: {
        Id: {in: ids},
        or:{
            Email: {like: '%test1%'},
            or:{
                and:{
                    firstname: {eq: 'dummy'},
                    lastname: {eq: 'dummy'},
                },
                Email: {like: '%test2%'} 
            }                                      
        }
    } 
}; 

Please vote for improvement on salesforce idea exchange

https://success.salesforce.com/ideaView?id=0873A000000LsEbQAK

|improve this answer|||||

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.