Hi,
We can write both batch and schedule in one class as both are interface we can implement more then one interface in one class which is basically known as multiple inheritance .
You can try like below-
global class BatchAndSchedule implements Schedulable,Database.Batchable<sObject>{
global Database.QueryLocator start(Database.BatchableContext BC){
String query = ‘SELECT Id,Name FROM Account’;
return Database.getQueryLocator(query);
}
global void execute(Database.BatchableContext BC, List<Account> scope){
for(Account acc : scope){
acc.Name = acc.Name +’ManojBatch’;
}
update scope;
}
global void finish(Database.BatchableContext BC){ }
global void execute(SchedulableContext scon) {
Database.executeBatch(new BatchAndSchedule(),100);
}
}
Thanks.