I know this question has been answered in few places my scenario is a bit different I think.
I'm building a dynamic SOQL query, the WHERE
clause is going to be dynamic.
I have a List<String> values
in which values are stored from VF page using input fields and later this list is used to query records.
My VF page allows users to select fields (these fields will be added to the where clause) on a certain object that will allow them query records.
So, Let's say a user selects Age__c
field from the VF page which is of type Double
and then the user fills in the input fields with Age values.
This is how the query will look like:
SELECT Id, Some_Field__c FROM Some_Object__c WHERE Age__c IN :values
This query fails to execute since the type of Age__c is Double and the collection passed as a filter is List<String>
. I then converted this list to a List<Object>
and that's when it throws the below error:
Invalid bind expression type of ANY for column of type Decimal
How can I typecast this values
list to make this work?
How can I solve this issue? Any help will be appreciated.
WHERE
clause), you'll probably need to make a Describe call to get the field's type. I would then try fully Dynamic SOQL and construct the WHERE clause as a string based upon the value type.