0

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];
  • Which line is 175? What type of object is surveyRef? – Adrian Larson Feb 8 '17 at 4:52
  • 1
    Your missing some key parts of the code that could help. Namely the parts where the variables are declared – Eric Feb 8 '17 at 5:06
4

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.

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];
Set<String> dependentQuestions = new Set<String>();
for (MM_Survey_Question__c surveyQuestion : DQlist) {
    dependentQuestions.add(surveyQuestion.Dependent_Question__c);
}
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:dependentQuestions];

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?

  • I'm glad, kiran – Brent Bow Feb 8 '17 at 19:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.