2

I want to pass a list position to my dynamic query, but it does not evaluate. have someone try something like this :

      .......
      if(selectedType == Constants.settlementTypeAutre){
        query += ' and  numm__Tech_TypeCollectif__c NOT IN( :parameters[5],:parameters[6])'; 
    }else if(selectedType == Constants.settlementTypeFournisseur){
        query += ' and  numm__Tech_TypeCollectif__c IN( :parameters[5],:parameters[8])'; 
    }
    else if(selectedType == Constants.settlementTypeClient){
        query += ' and  numm__Tech_TypeCollectif__c IN( :parameters[6],:parameters[8])'; 
    } .....  

i don't want to create one variable by one, because i have 12 variables to put in this query. If there is no solution, then i will have to do it.

2
  • Have you tried NOT IN : ( parameters[5],parameters[6]) ? Commented Jun 17, 2014 at 7:24
  • in my example their is only the in, but there are also this : and numm__IdEstablishment__c = :parameters[0] , how should i reference this one ? the error im obtaining is : System.QueryException: unexpected token: '[' Commented Jun 17, 2014 at 7:36

2 Answers 2

5

The bind variables (:something) in dynamic SOQL must be a simple variable name that will still be a valid variable when the SELECT is actually executed. So:

  • :someVar is OK
  • :someArray[3] isn't
  • :someObject.someField isn't
  • :someFunction() also isn't

(all these are fine in regular [SELECT ...] statements, the limitation applies only for building queries as strings)

This was extensively covered in similar questions:

So I'd say you should make a helper variable (Set? List?) and depending on the conditions add your params to that helper. Then you can have single

query += ' and numm__Tech_TypeCollectif__c IN :helper';

regardless of the contents.

0

Can't you just create map of paramethers instead of list and just use selectedType as key?

Map<String, String[]> paramMap;

I have no idea what type are those values so I just used string.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.