How is the scheduled class called? Does your VF page schedule the class? For example (and correct me if I am wrong), is it like you have a VF page with a standard controller on, say, Account. And then you want the VF page to schedule the class to do something neat pertaining to the specific Account we're viewing on the VF page. If this is the case you could try the following:
You'd need to collect the id
of the record you're concerned with and pass that to the scheduled class. Then in the scheduled class, you need to create a new instance of your VF controller class, but to do this, you'll need to pass it an ApexPages.StandardController
for the id
that gave the scheduled class. "Cool," you may say, "but what about the error in calling ApexPages.currentPage().getParamters()
?" To overcome this obstacle (assuming you are using a standard controller), just use the getId
method of the ApexPages.StandardController
class.
Now, if you're not using a standard controller, (and even if you are) you can always create multiple initialization methods for your VF controller.
For example:
public class myVFController{
private id acctId;
// to be used as a controller for a VF page
public myVFController(){
acctId = ApexPages.CurrentPage().getParameters().get('id');
}
// so myVFController can be used as an extension for StandardController
public myVFController(ApexPages.StandardController con){
acctID = con.getId();
}
// to be used in your scheduled code
public myVFController(id acctId){
this.acctId = acctId;
}
}
And then in your scheduled class, make sure you initialize your VF controller by passing calling:
myVFController con = new myVFController(myAcctId);