Newer Version Available
Format and Options for Query Criteria Query Criteria
1<apex:remoteObjectsjsNamespace="RemoteObjectModel">
2 <apex:remoteObjectModel name="Contact" fields="FirstName,LastName"/>
3</apex:remoteObjects>
4
5<script>
6var ct = new RemoteObjectModel.Contact();
7ct.retrieve(
8 { where: {
9 FirstName: {eq: 'Marc'},
10 LastName: {eq: 'Benioff'}
11 },
12 orderby: [ {LastName: 'ASC'}, {FirstName: 'ASC'} ],
13 limit: 1 },
14
15 function(err, records) {
16 if (err) {
17 alert(err);
18 } else {
19 console.log(records.length);
20 console.log(records[0]);
21 }
22 }
23);
24</script>where Conditions
- eq: equals
- ne: not equals
- lt: less than
- lte: less than or equals
- gt: greater than
- gte: greater than or equals
- like: string matching. As with SOQL, use “%” as a wildcard character.
- in: in, used for finding a value that matches any of a set of fixed values. Provide values as an array, for example, ['Benioff', 'Jobs', 'Gates'].
- nin: not in, used for finding a value that matches none of a set of fixed values. Provide values as an array, for example, ['Benioff', 'Jobs', 'Gates'].
- and: logical AND, used for combining conditions
- or: logical OR, used for combining conditions
1{
2where:
3 {
4 or:
5 {
6 FirstName: { like: "M%" },
7 Phone: { like: '(415)%' }
8 }
9 }
10}Filter results based on a date range by using a combination of lte and gte. For example:
1<apex:remoteObjects jsNamespace="RemoteObjectModel">
2 <apex:remoteObjectModel name="Account" fields="Id,Name,CreatedDate"/>
3</apex:remoteObjects>
4
5<script>
6 var account_created_from_date = new Date('2017-01-01');
7 var account_created_to_date = new Date('2018-01-01');
8 var clauses = {
9 'where': {
10 'CreatedDate': { 'lte': account_created_to_date },
11 'and': {
12 'CreatedDate': { 'gte': account_created_from_date },
13 'Id': { 'ne': '' }
14 }
15 }
16 };
17
18 var ct = new RemoteObjectModel.Account();
19 ct.retrieve(
20 clauses,
21 function(err, records) {
22 if (err) {
23 console.log(err);
24 } else {
25 console.log(records.length);
26 console.log(records[0]);
27 }
28 }
29 );
30</script>orderby Conditions
orderby enables you to set a sort order for your results. You can sort on up to three fields.
1orderby: [ {Phone: "DESC NULLS LAST"} , {FirstName: "ASC"} ]limit and offset Conditions
limit and offset enable you to retrieve a specific number of records at a time and to page through an extended set of results.
Use limit to specify how many records to return in one batch of results. The default value is 20. The maximum is 100.
Use offset to specify how many records to skip in the overall result set before adding records to the returned results. The minimum is 1. The maximum offset is 2,000 rows. The response is based on the size and number of selected fields. Requesting an offset greater than 2,000 results in a NUMBER_OUTSIDE_VALID_RANGE error.