我使用jsforce find-api来搜索一个由道布创建的帐户,这是一个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次
我还尝试传递一个date对象:
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 query method chain to find data between 2 dates
但他们也帮不上忙
发布于 2021-03-25 06:47:02
错误在于将DateTime视为Date对象,并且在jsforce文档中缺少示例。
最后我终于弄明白了:
const birthDateObj = moment(birthDate, 'MM/DD/YYYY').toDate();
rawSObject = { [AccountFields.PersonBirthdate]: { $eq: SfDate.toDateLiteral(birthDateObj) };https://stackoverflow.com/questions/66790502
复制相似问题