Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot Update Custom Date field via SalesForce API (JSforce)

I'm using the JSforce library from a Node.js app to update a custom date field on an Opportunity object, but the field is not being updated. The response indicates that the update is successful and the SystemModstamp field is updated on the object, however the field remains null.

This is the JSforce call I'm using:

conn.sobject("Opportunity").update({
    Id: opportunityId,
    Contract_Cancelled_Date__c: new Date("2018-09-13")
}, function(err, ret) {
    if (err) {
        console.log(err);
    } else {
        console.log(ret);
    }
});

I've tried converting the date to a string: (new Date("2018-09-13")).toIsoString(). I've also tried passing in a string constant: "2018-09-13T00:00:00.000Z". All result in the same outcome.

I'm able to update other non-date custom fields without issue and I'm able to update the non-custom date field CloseDate successfully.

like image 963
Brady Avatar asked Jun 03 '26 20:06

Brady


1 Answers

You can use inbuilt classes provided by jsforce

for example

const { SfDate }   = require('jsforce');

// use toDateLiteral when the field is just Date type
const dateLiteral = SfDate.toDateLiteral( new Date() )

// use toDateTimeLiteral when the field is just Date/Time type
const dateLiteral = SfDate.toDateTimeLiteral(new Date())
like image 115
Debu Shinobi Avatar answered Jun 05 '26 13:06

Debu Shinobi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!