You need to sign in to do that
Don't have an account?
Abhishek Sharma 527
make the method Batchable
Hello Experts, I have a normal method which I want to make it Batchable as it should be executed on given time. It's the first time to work with Batch apex. Can anyone please guide how to implement this.
Any help would be highly appreciated.
public static void firebaseDashboardData(){ try { Map<Id,Integer> sessionCountMap= TBT_EventQuerySelector.getSessionCount(); Map<Id,Integer> activeSessionCountMap=TBT_EventQuerySelector.getActiveSessionCount(); List<DashboardWrapper> dashboardDataList=new List<DashboardWrapper>(); Set<Id> keySet = sessionCountMap.keySet(); for(Id key : keySet){ if(activeSessionCountMap.containsKey(key)) { DashboardWrapper data=new DashboardWrapper(); data.userId=key ; data.sessionCount=sessionCountMap.get(key ); data.activeSessionCount=activeSessionCountMap.get(key ); dashboardDataList.add(data); } } String body='{'; Http http = new Http(); HttpRequest request = new HttpRequest(); request.setEndpoint('https://test/UserDashboard.json'); request.setMethod('PATCH'); for(DashboardWrapper dW: dashboardDataList) { body=body+'"'+dw.userId+'" :'+JSON.serialize(dw)+','; } body=body.removeEnd(','); body=body+'}'; request.setBody(body); HttpResponse response = http.send(request); // If the request is successful, parse the JSON response. if(response.getStatusCode() == 200) { // Deserialize the JSON string into collections of primitive data types. Map<String, Object> results = (Map<String, Object>) JSON.deserializeUntyped(response.getBody()); System.debug(results); JSON.deserializeUntyped(response.getBody()); // System.debug(results); } } catch (Exception e) { throw new AuraHandledException(e.getMessage()); } }
Any help would be highly appreciated.
To make your method batchable, you need to implement the Database.Batchable interface and define the start, execute, and finish methods. Here's an example of how you can modify your code to make it batchable: If the above information helps , please mark this as Best Answer.
Thank you.