0

我正在使用 jsforce find-api 来按 DOB 搜索帐户,这是一个 type 字段Date

对 API 的调用如下所示:

const conn = await connection();
result = await conn.sobject(this.schema.Name).find(rawSObject, Object.keys(this.schema.Fields));

rawSObject如下所示:

试试 1

const rawSObject = { [AccountFields.PersonBirthdate]: moment(birthDate, 'MM/DD/YYYY').format('YYYY-MM-DD') };

但它失败了:

INVALID_FIELD: 
 PersonBirthdate = '1985-12-12'
                                      ^
ERROR at Row:1:Column:985
value of filter criterion for field 'PersonBirthdate' must be of type date and should not be enclosed in quotes

试试 2

const rawSObject = { [AccountFields.PersonBirthdate]: moment(birthDate, 'MM/DD/YYYY').toISOString();

但仍然得到同样的错误。

尝试 3

我还尝试传递一个日期对象:

const rawSObject = { [AccountFields.PersonBirthdate]: moment(birthDate, 'MM/DD/YYYY').toDate()

这一次我得到了一个不同的错误:

MALFORMED_QUERY: 
PersonBirthdate = Thu Dec 12 1985 00:00:00 GMT+0200
                               ^
ERROR at Row:1:Column:1002
Bind variables only allowed in Apex code
    at HttpApi.getError (/Users/nalfasi/dev/salesforce-gateway/node_modules/jsforce/lib/http-api.js:250:13)...

尝试 4

在搜索网络时,我还遇到了以下线程:https ://github.com/jsforce/jsforce/issues/851并尝试了那里的建议,特别是这里评论中的建议:https ://github.com/ jsforce/jsforce/issues/851#issuecomment-594233217

rawSObject = { [AccountFields.PersonBirthdate]: { $eq: SfDate.toDateTimeLiteral(birthDateObj) };

现在我遇到了一个新错误:

INVALID_FIELD: 
 PersonBirthdate = 1985-12-11T22:00:00Z
                                      ^
ERROR at Row:1:Column:985
value of filter criterion for field 'PersonBirthdate' must be of type date and should not be enclosed in quotes
    at HttpApi.getError (/Users/nalfasi/dev/salesforce-gateway/node_modules/jsforce/lib/http-api.js:250:13)

更远

我还搜索了网络并发现了以下问题: Cannot Update Custom Date field via SalesForce API (JSforce)

jsforce 查询方法链来查找 2 个日期之间的数据

https://salesforce.stackexchange.com/questions/22851/trouble-using-soql-to-filter-results-by-a-range-of-dates-what-is-the-correct-s

https://salesforce.stackexchange.com/questions/8896/using-a-date-for-a-datetime-field-in-a-soql-query

但他们也没有帮助

4

1 回答 1

1

错误是作为对象处理DateTime以及Datejsforce 文档中缺少示例的组合。

最后我能够弄清楚:

const birthDateObj = moment(birthDate, 'MM/DD/YYYY').toDate();
rawSObject = { [AccountFields.PersonBirthdate]: { $eq: SfDate.toDateLiteral(birthDateObj) };
于 2021-03-24T22:47:01.583 回答