+ Start a Discussion
Amit Visapurkar 5Amit Visapurkar 5 

Using includes in soql

 List<AggregateResult> g = [SELECT AVG(A) CurrentM) FROM Customer_Object __c WHERE  custom_field INCLUDES (:fleetM) GROUP BY custom_field];
fleetM  is a String whose values is like this -  'A','B' 
The question is when i use fleetM the query does not return anything however when i use INCLUDES ('A','B' ) it gives correct result.

Can anyone tell me whats the problem. The query is returning correct results when the second approach is used and no result with first appraoch.
 
Amit Visapurkar 5Amit Visapurkar 5
I want to know what the problem is : Whether we have to use Dynamic query to get the desired result. If yes why
Amit Singh 1Amit Singh 1
Yes, You can use in SOQL refere below link
https://salesforce.stackexchange.com/questions/46196/soql-query-with-multi-select-picklist-in-where-clause (https://salesforce.stackexchange.com/questions/46196/soql-query-with-multi-select-picklist-in-where-clause" target="_blank)
Amit Visapurkar 5Amit Visapurkar 5
Is the way i am writing soql is incorrect. I have created a String fleetM whose format is like this -  'A','B' and then used in the query. Then why is it giving incorrect results. 
Amit Singh 1Amit Singh 1
I do not think u are making correct SOQL. Make a debug after query and see if SOQL format if right.
Amit Visapurkar 5Amit Visapurkar 5
When i am hardcoding value in includes List<AggregateResult> g = [SELECT AVG(A) CurrentM) FROM Customer_Object __c WHERE  custom_field INCLUDES ('A') GROUP BY custom_field]; i am getting correct result .

Only when i use 
List<AggregateResult> g = [SELECT AVG(A) CurrentM) FROM Customer_Object __c WHERE  custom_field INCLUDES (:fleetM) GROUP BY custom_field]; i am not getting the result. Can anybody tell me why this is happening