[SalesForce] Invalid bind expression type of String for column of type Date

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


 String s=string.valueOf(dt);

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

Best Answer

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.