Activity › Forums › Salesforce® Discussions › How to schedule a batch class without scheduler class in salesforce?
-
How to schedule a batch class without scheduler class in salesforce?
Posted by Deepak on November 15, 2019 at 11:15 AMHow to schedule a batch class without scheduler class in salesforce?
Yogesh replied 6 years, 6 months ago 3 Members · 2 Replies -
2 Replies
- [adinserter block='9']
-
Hello ,
you can get help from this code below:-
public class keepTruckInBatchForVehicleUpadte implements database.Batchable<decimal>, Database.AllowsCallouts, database.stateful, schedulable
{
public List<decimal> pageList;
public boolean executeNext;
public List<Vehicle_Update__c> lastvehicleUpdates;
public keepTruckInBatchForVehicleUpadte()
{
executeNext=false;
pageList = new List<decimal>();
}
public keepTruckInBatchForVehicleUpadte(List<decimal> counts, boolean bool)
{
executeNext = bool;
pageList = new List<decimal>();
pageList.addAll(counts) ;
}
public iterable<decimal> start(Database.BatchableContext BC)
{
return pageList;
}
public void execute(Database.BatchableContext BC, List<decimal> scope)
{
decimal count = scope[0];
keepTruckInApiCallouts.getVehicleLocations(count);
string returnResponse = keepTruckInApiCallouts.getVehicleLocations(count);
keepTruckInApiCallouts.keepTruckVehicleUpdate(returnResponse);
// Deserializes the returnResponse JSON string into collections of primitive data types.
Map<String, Object> jsonObjects = (Map<String, Object>) JSON.deserializeUntyped(returnResponse);
Map<String, Object> paginationobjs = (Map<String, Object>)jsonObjects.get(‘pagination’);
decimal totalRecords = integer.valueof(paginationobjs.get(‘total’));
decimal perPageRecs = integer.valueof(paginationobjs.get(‘per_page’));
decimal totalPages = math.ceil(totalRecords/perPageRecs);
if(totalRecords > perPageRecs && executeNext == true)
{
pageList.clear();
for(count = 2; count <= totalPages; count++)
{
pageList.add(count);
}
}
else
{
executeNext = false;
}
}
public void finish(Database.BatchableContext BC)
{
if(executeNext == true)
{
database.executeBatch((new keepTruckInBatchForVehicleUpadte(pageList, false)),1);
}
}
public void execute(SchedulableContext SC)
{
lastVehicleUpdates = [select id from Vehicle_Update__c];
delete lastVehicleUpdates;
database.executebatch((new keepTruckInBatchForVehicleUpadte(new List<decimal>{1}, true)),1);
}
}
Log In to reply.