3

With the Rest Toolkit, creating or updating an optional date field with an empty string results in an Invalid date error. Using null instead results in another error: Argument 1 cannot be null.

How can you make the field null?

client.update('Transaction__c', 'a0Ni0000000H1kWCHA', {Name: "1078", Date__c: "2013-03-14", Due_Date__c: ""}, function(){})
  • 1
    Can you not just use the value null? – Matt Lacey May 21 '13 at 4:24
  • Could you please share some of your code? – doga May 21 '13 at 10:19
  • @LaceySnr: I've tried null to no avail. – geeljire May 21 '13 at 13:54
  • Sorry, that looks like my bug. You'll see that other types convert an empty string to null: bit.ly/10W3MIE If you fix it before I get a chance, please open a pull request. – xn. May 23 '13 at 18:47
  • Fixed and working. Thanks for the tip: bit.ly/170bhFK – geeljire May 27 '13 at 16:47
1

It sounds like this could be a limitation of the toolkit. If the remoting is being done in a VF page you could instead call a method your own apex method which could look for a specific date such as 01-01-1900 and set it to null when needed.

If you're outside of the platform (sounds like you might be) and really need this functionality then you could use a similar approach, set a specific date that wouldn't be used otherwise (01/01/1900) and then use a trigger to set that field to null.

1

Convert the empty string to null in RemoteTKController.cls by changing

obj.put(key, Date.valueOf(svalue));

to

obj.put(key, svalue == '' ? null : Date.valueOf(svalue));

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.