You need to sign in to do that
Don't have an account?
COMPILE ERROR: Variable is not visible
I have this Batch Apex codes out Salesforce help page. I tried it and I kept getting this error:
COMPILE ERROR: Variable is not visible: query
LINE: 3 COLUMN: 1
From the codes standpoint, I am not sure where the codes missed.
Here is the Apex class:
global class OwnerReassignment implements Database.Batchable<sObject>{
String query;
String email;
Id toId;
Id fromId;
global database.querylocator start(Database.BatchableContext BC){
return Database.getQueryLocator(query);}
global void execute(Database.BatchableContext BC, List<sObject> scope){
List<Account> accns = new List<Account>();
for(sObject s : scope){Account a = (Account)s;
if(a.Id==fromId){
a.Rating = 'Warm';
accns.add(a);
}
}
update accns;
}
global void finish(Database.BatchableContext BC){
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
mail.setToAddresses(new String[] {email});
mail.setReplyTo('briandowx@yahoo.com');
mail.setSenderDisplayName('Batch Processing');
mail.setSubject('Batch Process Completed');
mail.setPlainTextBody('Batch Process has completed');
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
}
}
Here is the Apex execute codes that I used to run in Workbench or System Log:
id u = '0017000000MHEYd';
OwnerReassignment reassign = new OwnerReassignment();
reassign.query = 'SELECT Id, Name, OwnerId FROM Account WHERE Id=\'' + u + '\'';
reassign.email = 'admin@acme.com';
reassign.fromId = '0017000000MHEYd';
reassign.toId = '0017000000MHEYd';
ID batchprocessid = Database.executeBatch(reassign);
Thank you in advance your help.
Brian
Check with defining the Variable as global.
All Answers
Check with defining the Variable as global.
Hi,
Please declare the required variable as global.