• Sriyesh M 18
  • NEWBIE
  • 0 Points
  • Member since 2021

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 3
    Replies
Hi All,
 
I am trying to pass a list of records into a batch class using constructor. And adding that to the query. But I am getting the following error :
First error: Only variable references are allowed in dynamic SOQL/SOSL. Can someone help.
 
Code :- 
String query = 'SELECT Id, Name, ProductCode FROM Product2 WHERE IsActive =true';
public ConstructorName(List<Product2> productlst){
        if (!productlst.isEmpty() && productlst!=null) {
            query += ' AND APTS_EXT_ID__c IN : '+productlst; 
        }
    }
global Database.QueryLocator start(Database.BatchableContext bc) {
        return Database.getQueryLocator(query);
    }
Hi All,
 
I am trying to pass a list of records into a batch class using constructor. And adding that to the query. But I am getting the following error :
First error: Only variable references are allowed in dynamic SOQL/SOSL. Can someone help.
 
Code :- 
String query = 'SELECT Id, Name, ProductCode FROM Product2 WHERE IsActive =true';
public ConstructorName(List<Product2> productlst){
        if (!productlst.isEmpty() && productlst!=null) {
            query += ' AND APTS_EXT_ID__c IN : '+productlst; 
        }
    }
global Database.QueryLocator start(Database.BatchableContext bc) {
        return Database.getQueryLocator(query);
    }