Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

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.

share|improve this question
    
Have you tried NOT IN : ( parameters[5],parameters[6]) ? –  highfive Jun 17 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: '[' –  vanessen Jun 17 at 7:36

2 Answers 2

up vote 3 down vote accepted

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.

share|improve this answer

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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