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
srinivas pulipatisrinivas 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>
Best Answer chosen by srinivas pulipati
Prashant WayalPrashant Wayal
Hi Srinivas,

Please try below code:
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.
              return null;
        }
}

Hope it helps you.

Thanks,
Prashant

All Answers

Prashant WayalPrashant Wayal
Hi Srinivas,

Please try below code:
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.
              return null;
        }
}

Hope it helps you.

Thanks,
Prashant
This was selected as the best answer
srinivas pulipatisrinivas pulipati
thank u prasanth
srinivas pulipatisrinivas pulipati
prasanth code is execute sucessfully but when click on preview button out showing some error