+ Start a Discussion
SunnyShinySunnyShiny 

Variable does not exist

hello

 

I try to run a batch throught the developer console but Ive got variable val does not exist>

 

String val = 'Sales';
String soqlQuery = 'Select id  from Contact  Where RecordType.Name =:val  limit 1';
system.debug(soqlQuery);

Id batchInstanceId = Database.executeBatch(new BATCH_UpdateObject('Select id  from Contact  Where RecordType.Name in:val  limit 1','Contact','',''), 10);

 

Thanks for your help

Naidu PothiniNaidu Pothini
String val = 'Sales';
String soqlQuery = 'Select id  from Contact  Where RecordType.Name =\''+val+'\' limit 1';
system.debug(soqlQuery);

 try this.

Rahul SharmaRahul Sharma

Hello ,

 

The problem is in yor last line where you are calling the batch class.

While passing you are passing the String Query which has Local variable but does not exist in batch class.
So instead of passing it as a query with variable, use query as 

 

String val = 'Sales';
String soqlQuery = 'Select id from Contact Where RecordType.Name =\''+val+'\' limit 1';
system.debug(soqlQuery);
Id batchInstanceId = Database.executeBatch(new BATCH_UpdateObject(soqlQuery,'Contact','',''), 10);

 Try something like this and let us know if it you still face any issues.