SyncMadeEasy/force-app/main/default/classes/Batchtodeletelogs.cls

42 lines
2.7 KiB
OpenEdge ABL

/**
* ─────────────────────────────────────────────────────────────────────────────────────────────────┐
* This Batch class is use for delete all older log records more then 30 dys old.
* Shopify API Documentation: https://shopify.dev/docs/admin-api/rest/reference
* Create Shopify Store: https://www.shopify.com/signup?itcat=identity&itterm=create-new-store
* Shopify API Release 2020: https://www.shopify.in/partners/blog/shopify-api-release-january-2020
* What is Person Account in Salesforce ? https://help.salesforce.com/articleView?id=account_person.htm&type=5
* ──────────────────────────────────────────────────────────────────────────────────────────────────
* @author Sumit <sumit@hicShopify.com>
* ──────────────────────────────────────────────────────────────────────────────────────────────────
*/
global with sharing class Batchtodeletelogs implements Database.Batchable<HIC_ShopifySync__shopify_log__c>,Database.Stateful{
global Iterable<HIC_ShopifySync__shopify_log__c> start (Database.BatchableContext bc){
list<HIC_ShopifySync__shopify_log__c> listofshopifylog = new list<HIC_ShopifySync__shopify_log__c>();
date d = system.today().addDays(-30);
listofshopifylog = [select id from HIC_ShopifySync__shopify_log__c where createdDate <= :d WITH SECURITY_ENFORCED limit 9999 ];
if(!listofshopifylog.isEmpty()){
return listofshopifylog;
}else{
list<HIC_ShopifySync__shopify_log__c> listofemptyshopifylog = new list<HIC_ShopifySync__shopify_log__c>();
return listofemptyshopifylog;
}
}
global void execute(Database.BatchableContext bc ,list<HIC_ShopifySync__shopify_log__c> scope){
try{
if(!scope.isEmpty()){
if(CheckAccessibility.isDeletable('HIC_ShopifySync__shopify_log__c'))
Database.delete(scope,false);
}
}catch(exception e){
system.debug('getting errors when deleting logs');
}
}
global void finish(Database.BatchableContext bc){
system.debug('Delete logs successfully');
}
}