/****************************************************************************************************************** * Prime * Name : UpdateFanDeleteCountAtSdc_BatchProcess * Created By : [Satya] - Prime * Purpose : Batch process for deleting total fan related data when fan sends deletion request from PC * Created Date : 21 Nov 2020 * * Date Modified Modified By Description of the update ------------------------------------------------------------------------------------------------------------------- * ********************************************************************************************************************/ global class UpdateFanDeleteCountAtSdc_BatchProcess implements Database.Batchable, Database.RaisesPlatformEvents { global Database.QueryLocator start(Database.BatchableContext BC) { return Database.getQueryLocator( [ SELECT id, name, Fandeletecount__c FROM Subscription_Delete_Count__c WHERE CreatedDate = TODAY OR LastModifiedDate = TODAY ] ); } global void execute(Database.BatchableContext BC, List scope) { set AutoNmberIds = new Set(); Set SetSubIds = new Set(); List ListsubUpdate = new List(); List ListSDC = new List(); Map mapvsfd = new Map(); Map mapvSDC = new Map(); for (Subscription_Delete_Count__c sd : scope) { SetSubIds.add(sd.id); } List groupedResults = [ SELECT Subscription_Count_ID__c, count_distinct(Fan_Duplicate_ID__c) t FROM Fan_Delete_Count__c WHERE Subscription_Count_ID__c IN :SetSubIds GROUP BY Subscription_Count_ID__c ]; Integer size = groupedResults.size(); for (AggregateResult ar : groupedResults) { Id custid = (ID) ar.get('Subscription_Count_ID__c'); Integer count = (INTEGER) ar.get('t'); Subscription_Delete_Count__c cust1 = new Subscription_Delete_Count__c(Id = custid); cust1.Fandeletecount__c = count; mapvSDC.put(cust1.id, cust1); } update mapvSDC.Values(); } global void finish(Database.BatchableContext BC) { } }