function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ 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.