jsforce query method chain to find data between 2 dates

755 Views Asked by At

I have written SOQL query to get the data between 2 dates 2020-06-01 and 2020-06-30

SELECT Id ,LastModifiedDate
FROM Account  
WHERE LastModifiedDate >= 2020-06-01T00:00:00Z
AND LastModifiedDate <= 2020-06-30T23:59:59Z

but I want to implement it using method chain

1

There are 1 best solutions below

0
On

See this link for information on how to convert a string representation of a SF date to a date literal.

The rest is just a modification for the official docs per your query.

(async _ => {
    const results = await conn.sobject("Account")
          .find(
            // conditions in JSON object
            { 
              LastModifiedDate : { $gte : jsforce.SfDate.toDateTimeLiteral('2020-06-01T00:00:00Z'), $gte : jsforce.SfDate.toDateTimeLiteral('2020-06-30T23:59:59Z') },
            },
            // fields in JSON object
            { 
              Id: 1,
              LastModifiedDate: 1
            }
          ) // end method chain
          console.log(results)
})()