From f90c63155656928b86f1ce1d91a134de3d12d2b9 Mon Sep 17 00:00:00 2001
From: Li Jun <buli@deloitte.com.cn>
Date: 星期三, 27 四月 2022 18:26:41 +0800
Subject: [PATCH] SyncAContact0427
---
force-app/main/default/classes/SyncAccountContactToAWS.cls | 40 ++++++++++++++++++++++++++++++++++------
1 files changed, 34 insertions(+), 6 deletions(-)
diff --git a/force-app/main/default/classes/SyncAccountContactToAWS.cls b/force-app/main/default/classes/SyncAccountContactToAWS.cls
index df049b2..50e9478 100644
--- a/force-app/main/default/classes/SyncAccountContactToAWS.cls
+++ b/force-app/main/default/classes/SyncAccountContactToAWS.cls
@@ -10,15 +10,24 @@
global class SyncAccountContactToAWS implements Schedulable,Database.Batchable<SObject>,Database.AllowsCallouts{
global String query;
-
+ global String scheduleId{set;get;}
global SyncAccountContactToAWS(String query) {
this.query = query;
}
global SyncAccountContactToAWS() {
this.query = 'SELECT id,Doctor_Division1__c,Doctor_Division1_Encrypted__c,Name,Name_Encrypted__c,Type__c,Type_Encrypted__c,AWS_Data_Id__c,Contact__c, Contact__r.Doctor_Division1_Encrypted__c,Contact__r.LastName_Encrypted__c, Contact__r.Type_Encrypted__c FROM Agency_Contact__c WHERE AWS_Data_Id__c =\'\' And Contact__c != null order by lastmodifieddate desc';
}
+ global SyncAccountContactToAWS(String query,String scId) {
+ if(String.isBlank(query)||String.isEmpty(query)){
+ this.query = 'SELECT id,Doctor_Division1__c,Doctor_Division1_Encrypted__c,Name,Name_Encrypted__c,Type__c,Type_Encrypted__c,AWS_Data_Id__c,Contact__c, Contact__r.Doctor_Division1_Encrypted__c,Contact__r.LastName_Encrypted__c, Contact__r.Type_Encrypted__c FROM Agency_Contact__c WHERE AWS_Data_Id__c =\'\' And Contact__c != null order by lastmodifieddate desc';
+ }else{
+ this.query = query;
+ }
+ system.debug('This query from Batch:'+this.query);
+ this.scheduleId = scId;
+ }
global Database.QueryLocator start(Database.BatchableContext bc) {
- system.debug('Query by custom soql:'+this.query);
+ system.debug('Query by custom soql:'+this.query);
return Database.getQueryLocator(this.query);
}
global void execute(Database.BatchableContext BC, list<Agency_Contact__c> scope) {
@@ -35,22 +44,41 @@
}
global void execute(SchedulableContext SC) {
- Id execBTId = Database.executeBatch(new SyncAccountContactToAWS(), 1);
+ system.debug('this query from schedule execute method:'+this.query);
+ Id execBTId = Database.executeBatch(new SyncAccountContactToAWS(this.query,SC.getTriggerId()), 1);
+ system.debug('Batch Job Id:'+execBTId);
}
- public static void assignOnceOneMinuteLater() {
+ public static void assignOnceOneMinuteLater(List<Agency_Contact__c> acList) {
+ system.debug('ACList:'+JSON.serialize(acList));
String hour = String.valueOf(Datetime.now().hour());
String min = String.valueOf(Datetime.now().minute() + 1);
String ss = String.valueOf(Datetime.now().second());
//parse to cron expression
String nextFireTime = ss + ' ' + min + ' ' + hour + ' * * ?';
- SyncAccountContactToAWS s = new SyncAccountContactToAWS();
- System.schedule('Job Started At ' + String.valueOf(Datetime.now()), nextFireTime, s);
+ //Prepare the soql to agency account
+ String soqlForAgencyAccount = '';
+ if(acList!=null && acList.size()>0){
+ soqlForAgencyAccount = 'SELECT id,Doctor_Division1__c,Doctor_Division1_Encrypted__c,Name,Name_Encrypted__c,Type__c,Type_Encrypted__c,AWS_Data_Id__c,Contact__c, Contact__r.Doctor_Division1_Encrypted__c,Contact__r.LastName_Encrypted__c, Contact__r.Type_Encrypted__c FROM Agency_Contact__c WHERE id in ';
+ List<String> acIds = new List<String>();
+ for(Agency_Contact__c ac:acList ){
+ acIds.add(ac.Id);
+ }
+ soqlForAgencyAccount = soqlForAgencyAccount + '(\'' + String.join(acIds, '\', \'') + '\')';
+ }
+ system.debug('SOQL for agency:'+soqlForAgencyAccount);
+ SyncAccountContactToAWS s = new SyncAccountContactToAWS(soqlForAgencyAccount);
+ System.schedule('SyncAccountContactToAWS:' + String.valueOf(Datetime.now()), nextFireTime, s);
}
global void finish(Database.BatchableContext BC) {
+ system.debug('Finish batch job Id:'+BC.getJobId());
AsyncApexJob a = [SELECT Id, Status, NumberOfErrors, JobItemsProcessed, TotalJobItems, CreatedBy.Email FROM AsyncApexJob WHERE Id = :BC.getJobId()];
//then use the active job id and abort it
system.abortJob(a.id);
+ system.debug('Finish schedule job Id:'+scheduleId);
+ if(scheduleId!=null&&scheduleId!=''){
+ system.abortJob(scheduleId);
+ }
}
}
\ No newline at end of file
--
Gitblit v1.9.1