You need to sign in to do that
Don't have an account?
srinivas pulipati
I am writing schedule apex program but below error is came repetedly please rectify that one ?
MyNewBatch: [this code is correct]
global class MyNewBatch implements Database.Batchable<Sobject> {
global Database.QueryLocator start(Database.BatchableContext bc){
return Database.getQueryLocator('select id,name from account');
}
global void execute(Database.BatchableContext bc,list<Sobject> scope){
List<Account> acc=new List<Account>();
for(Sobject x:scope ){
Account a=(Account) x;
a.name ='Mr'+a.name;
acc.add(a);
}
update acc;
}
global void finish(Database.BatchableContext bc){
}
}
MySchedule : [this program also related to above program tjhis one also corrrect and execute]
global class MySchedule implements Schedulable{
global void execute(SchedulableContext sc){
MyNewBatch mb = new MyNewBatch();
Database.executebatch(mb);
}
}
TestSchedule :[this program have an error ]
public class TestSchedule {
public PageReference show(){
String timeframe ='0 10 8 10 * ?';
MySchedule ms= new MySchedule();
System.schedule('MyJob', timeframe, ms); //Error: Non-void method might not return a value or might have statement after a return statement.
}
}
Vf Page:
<apex:page contentType="TestSchedule">
<apex:form>
<apex:commandButton value="click" action="{!show}"/>
</apex:form>
</apex:page>
global class MyNewBatch implements Database.Batchable<Sobject> {
global Database.QueryLocator start(Database.BatchableContext bc){
return Database.getQueryLocator('select id,name from account');
}
global void execute(Database.BatchableContext bc,list<Sobject> scope){
List<Account> acc=new List<Account>();
for(Sobject x:scope ){
Account a=(Account) x;
a.name ='Mr'+a.name;
acc.add(a);
}
update acc;
}
global void finish(Database.BatchableContext bc){
}
}
MySchedule : [this program also related to above program tjhis one also corrrect and execute]
global class MySchedule implements Schedulable{
global void execute(SchedulableContext sc){
MyNewBatch mb = new MyNewBatch();
Database.executebatch(mb);
}
}
TestSchedule :[this program have an error ]
public class TestSchedule {
public PageReference show(){
String timeframe ='0 10 8 10 * ?';
MySchedule ms= new MySchedule();
System.schedule('MyJob', timeframe, ms); //Error: Non-void method might not return a value or might have statement after a return statement.
}
}
Vf Page:
<apex:page contentType="TestSchedule">
<apex:form>
<apex:commandButton value="click" action="{!show}"/>
</apex:form>
</apex:page>
Please try below code:
Hope it helps you.
Thanks,
Prashant
All Answers
Please try below code:
Hope it helps you.
Thanks,
Prashant