function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Anand@SAASAnand@SAAS 

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?

 

incuGuSincuGuS

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.

Anand@SAASAnand@SAAS

Using List<String> does'nt compile.

incuGuSincuGuS

What doesnt compile exactly?

Anand@SAASAnand@SAAS


This is the error

Compile error at line 15 column 29
Invalid bind expression type of LIST:String for column of type String Compile error at line 15 column 29Invalid bind expression type of LIST:String for column of type String

 

 

Greg FeeGreg Fee

Hello ,

 

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

 

jjvdevjjvdev

Greg,

 

I am running into a similar issue and getting this error when attempting to bind a list directly to the includes.

 

expecting a left parentheses, found ':'

 

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

Greg FeeGreg Fee

Hi jjvdev,

 

Can you post the snippet of code that is producing that?

 

Thanks,

 

Greg

jjvdevjjvdev

Here you go, thanks.

 

//Create a collection of priority categories picklist values for opportunities that qualify for assignment
Set<String> priorityCategory = new Set<String>();
	
for (Opportunity opp: trigger.new) {
		
if(!priorityCategory.contains(opp.ADK_Priority_Category__c)) {
priorityCategory.add(opp.ADK_Priority_Category__c);
}
		
if(opp.IsWon==True && opp.RecordTypeId=='012600000000zmi' && trigger.isUpdate==True && opp.ADK_Priority_Category__c!=null) {
			
//Which account manager should be assigned to the opportunities
List<Round_Robin_Participant__c> participant = [Select User__c From Round_Robin_Participant__c Where ADK_Priority_Category__c INCLUDES :priorityCategory limit 1];
Id userId = participant.get(0).User__c;

 

 

Greg FeeGreg Fee

You are right!  That is a pretty lame limitation. :(

 

 

wharlen.pimentelwharlen.pimentel
Hi, many years after... but the answer is:
Field__c includes (:variable)