Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * @author Mateusz Bednarek
- * @description Batch class used to send reminder email from Extenstions to Customer and General Constructor
- */
- global without sharing class ExtensionDateEmailBatch implements Database.Batchable<sObject> {
- global static final String HALF_TIME_EMAIL = 'Informacja o upłynięciu połowy terminu usterek';
- global static final String END_TIME_TO_CUSTOMER = 'Informacja o upłynięciu terminu usterek do klienta';
- global static final String END_TIME_TO_GW = 'Informacja o upłynięciu terminu usterek';
- String query = '';
- global ExtensionDateEmailBatch() {
- query = 'select id, Today__c, RecordType.DeveloperName, Status__c, Half_Time_to_Fix_Defects_GW__c, Due_Date_For_General_Contractor__c,Due_Date_for_Client__c from Extension__c';
- }
- global Database.QueryLocator start(Database.BatchableContext BC) {
- return Database.getQueryLocator(query);
- }
- global void execute(Database.BatchableContext BC, List<Extension__c> scope) {
- String halfTimeTemplate = [SELECT Id FROM EmailTemplate WHERE Name = :HALF_TIME_EMAIL LIMIT 1].Id;
- String endTimeCustomerTemplate = [SELECT Id FROM EmailTemplate WHERE Name = :END_TIME_TO_CUSTOMER LIMIT 1].Id;
- String endTimeToGW = [SELECT Id FROM EmailTemplate WHERE Name = :END_TIME_TO_GW LIMIT 1].Id;
- Map<String, List<Extension__c>> extenstionMapToSend = new Map<String,Extension__c>();
- List<Extension__c> halfTimeToGwExtenstionList = new List<Extension__c>();
- List<Extension__c> endTimeExtenstionList = new List<Extension__c>();
- for(Extension__c extenstion : scope) {
- //Send half time email to General Constructor
- if(extenstion.RecordType.DeveloperName ='Failure' && extenstion.Status__ != 'Fixed' && extenstion.Status__c != 'Fixed by the contractor' && extenstion.Today__c == extenstion.Half_Time_to_Fix_Defects_GW__c ){
- halfTimeToGwExtenstionList.add(extenstion);
- }
- //Send end time email to Customer and GW when expiration time passed
- if((extenstion.RecordType.DeveloperName ='Failure' || extenstion.RecordType.DeveloperName ='Handover_Failure' || extenstion.RecordType.DeveloperName ='Common_Failure')
- && extenstion.Today__c == extenstion.Half_Time_to_Fix_Defects_GW__c && extenstion.Status__ != 'Fixed' && extenstion.Status__c != 'Fixed by the contractor' ){
- endTimeExtenstionList.add(extenstion);
- }
- }
- if(halfTimeToGwExtenstionList.size() > 0){
- extenstionMapToSend.put(halfTimeTemplate,halfTimeToGwExtenstionList);
- }
- if(endTimeExtenstionList.size() > 0){
- extenstionMapToSend.put(endTimeCustomerTemplate,endTimeExtenstionList);
- extenstionMapToSend.put(endTimeToGW,endTimeExtenstionList);
- }
- try{
- //ResourceReservation.manextenstionMapToSend.put(ageReservationStatus(salesProcessesToUpdateQueue);
- ExtensionManager.sendExpirationReminderEmail(extenstionMapToSend);
- } catch(Exception e) {
- System.debug('Batch update failed. Details: '+e);
- }
- }
- global void finish(Database.BatchableContext BC) {
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement