I have to check where the Ids exists in the List of Strings
In the following code, Dependent_Question__c
is a text field which stores the record id. I am getting this in DQList
and checking these list in the below query using IN
operator and I am getting this error:
Error: Compile Error: Invalid bind expression type of MM_Survey_Question__c for column of type String at line 175 column 175
Why am I getting this error and how can I fix it?
List<MM_Survey_Question__c> DQlist=new List<MM_Survey_Question__c>();
DQlist=[select Dependent_Question__c from MM_Survey_Question__c where MM_Survey__c=:surveyRef and Dependent_Question__c!=null];
System.debug('DQ List---'+DQlist);
if(dependentQuestion!=null)
{
dependentQuestionOptions = new List<SelectOption>();
List<MM_Survey_Question__c> qlst = [Select Id, Name From MM_Survey_Question__c where MM_Survey__c=:surveyRef and Type__c='Single Select' and Dependent_Question__c IN:DQlist];
Best Answer
The problem is in the final portion of your last query's WHERE clause:
Dependent_Question__c IN:DQlist
Since the Dependent_Question__c field on the MM_Survey_Question__c object is a Text (String) field, DQlist would need to be a Set or List of type String, rather than type MM_Survey_Question__c as it is from the query return. In order to extract the Dependent_Question__c field values from each of the MM_Survey_Question__c records in DQlist, you will need to iterate through the list and collect a set of strings to use in the WHERE clause.
Stepping back a bit, though, why are you repeating the same query on your second and last lines, with only the added filter of
Type__c='Single Select'
? Why not include the Type__c filter in the original query?