dt = restReq.params.get('date');

 String s=string.valueOf(dt);

I am trying to convert date to string and i am getting this error.


That error means that your SOQL is trying to bind a Date field to a String value:

String s = String.valueOf(dt);
sobject[] records = [select ... from ... where somedatefield = :s];

Instead, you will want to make the variable a date:

Date d = DateTime.valueOf(dt);
sobject[] records = [select ... from ... where somedatefield = :d];

Note: You'll need to determine which DateTime method you need (e.g. DateTime.parse, etc) based on the date's format.

  • Thanks it worked perfectly. Cheers!! – videet boob Nov 20 '19 at 7:24

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.