You need to sign in to do that
Don't have an account?

Bind parameters in SOQL INCLUDE
Does bind parameters work when they appear in the "INCLUDES" clause of SOQL. Here's my observation
String userTypes='\'All\',\'Avon Leader\''; String titleLevels='\'All\',\'4\''; String SPLASHPAGE_TYPE='Splash Page'; System.debug('>>>>>>>>>>>>>>>userTypes='+userTypes); System.debug('>>>>>>>>>>>>>>>titleLevels='+titleLevels); List<Market_Content__c> mcList = [select Type__c,Content_Type__c,Content__c, User_Type__c, Title_Levels__c, Market__r.Name from Market_Content__c where Type__c='Splash Page' and Market__r.Market_Id__c = 'RO' and User_Type__c includes (:userTypes) and Title_Levels__c includes (:titleLevels) order by CreatedDate];
This SOQL returns 0 rows. However the following SOQL returns 1 row:
List<Market_Content__c> mcList = [select Type__c,Content_Type__c,Content__c, User_Type__c, Title_Levels__c, Market__r.Name from Market_Content__c where Type__c='Splash Page' and Market__r.Market_Id__c = 'RO' and User_Type__c includes ('All','Avon Leader') and Title_Levels__c includes ('All','4') order by CreatedDate];
What am I missing?
Try passing the parameter as a List<String> instead of a CSV string.
IE: List<String> userTypes , instead of String userTypes.
I can't test right now, Let me know if that solved it.
Gaston.
Using List<String> does'nt compile.
What doesnt compile exactly?
This is the error
Hello Anand@SAAS,
I think this syntax works:
List<String> userTypes = ...
List<String> titleLevels = ...
List<Market_Content__c> mcList = [select Type__c,Content_Type__c,Content__c, User_Type__c,
Title_Levels__c, Market__r.Name
from Market_Content__c
where Type__c='Splash Page'
and Market__r.Market_Id__c = 'RO'
and User_Type__c includes :userTypes
and Title_Levels__c includes :titleLevels
order by CreatedDate];
Using parentheses around the variable bind will put that value in a list., which would give you a list<list<string>> in this case and I think it what causes the compilation error you observed. The syntax above, without parentheses, will bind the list directly to the includes.
Hope that helps,
Greg Fee
salesforce.com
Greg,
I am running into a similar issue and getting this error when attempting to bind a list directly to the includes.
Also, according to the documentation "Using Apex Variables in SOQL and SOSL Queries", "Bind expressions can't be used with other clauses, such as INCLUDES."
-Thanks
Hi jjvdev,
Can you post the snippet of code that is producing that?
Thanks,
Greg
Here you go, thanks.
You are right! That is a pretty lame limitation. :(