I have a Batch class and I am trying to reference a Set in the WHERE clause of a dynamic SOQL query but I have an error: System.QueryException: expecting a colon, found '{kA09E0000005mCySAI}'
when using the syntax:
query = 'Select Id, KnowledgeArticleId, Known_Error_Status__c FROM Knowledge__kav WHERE PublishStatus=\'Online\'' +
' AND KnowledgeArticleId IN \''+kesIds+'\' LIMIT 1';
I have also tried to use the syntax below but another error appears: Variable kesIds does not exist:
query = 'Select Id, KnowledgeArticleId, Known_Error_Status__c FROM Knowledge__kav WHERE PublishStatus=\'Online\'' +
'AND KnowledgeArticleId IN :kesIds';
How can I fix the errors and reference my Set kesIds in the Dynamic SOQL? Thanks
here is a snippet of my batch:
global class BatchArticleEmail implements Schedulable, Database.Batchable<SObject> {
global string query;
// To schedule batch
global void execute(SchedulableContext sc) {
Id batchProcessId = Database.executeBatch(this);
}
// Constructor to query articles
global BatchArticleEmail() {
Set<Id> kesIds = new Set<Id>();
List<Known_Error_Subscription__c> kesList = [SELECT KnowledgeKA__c FROM Known_Error_Subscription__c];
for(Known_Error_Subscription__c kes : kesList) {
kesIds.add(kes.KnowledgeKA__c);
}
query = 'Select Id, KnowledgeArticleId, Known_Error_Status__c FROM Knowledge__kav WHERE PublishStatus=\'Online\'' +
' AND KnowledgeArticleId IN \''+kesIds+'\' LIMIT 1';
System.debug('query BatchArticleEmail ' +query);
}