Advertisement
Guest User

Untitled

a guest
Jul 27th, 2017
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.18 KB | None | 0 0
  1. /**
  2. * @author Mateusz Bednarek
  3. * @description Batch class used to send reminder email from Extenstions to Customer and General Constructor
  4. */
  5.  
  6. global without sharing class ExtensionDateEmailBatch implements Database.Batchable<sObject> {
  7. global static final String HALF_TIME_EMAIL = 'Informacja o upłynięciu połowy terminu usterek';
  8. global static final String END_TIME_TO_CUSTOMER = 'Informacja o upłynięciu terminu usterek do klienta';
  9. global static final String END_TIME_TO_GW = 'Informacja o upłynięciu terminu usterek';
  10.  
  11. String query = '';
  12.  
  13. global ExtensionDateEmailBatch() {
  14. 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';
  15. }
  16.  
  17. global Database.QueryLocator start(Database.BatchableContext BC) {
  18. return Database.getQueryLocator(query);
  19. }
  20.  
  21. global void execute(Database.BatchableContext BC, List<Extension__c> scope) {
  22. String halfTimeTemplate = [SELECT Id FROM EmailTemplate WHERE Name = :HALF_TIME_EMAIL LIMIT 1].Id;
  23. String endTimeCustomerTemplate = [SELECT Id FROM EmailTemplate WHERE Name = :END_TIME_TO_CUSTOMER LIMIT 1].Id;
  24. String endTimeToGW = [SELECT Id FROM EmailTemplate WHERE Name = :END_TIME_TO_GW LIMIT 1].Id;
  25.  
  26.  
  27. Map<String, List<Extension__c>> extenstionMapToSend = new Map<String,Extension__c>();
  28. List<Extension__c> halfTimeToGwExtenstionList = new List<Extension__c>();
  29. List<Extension__c> endTimeExtenstionList = new List<Extension__c>();
  30.  
  31. for(Extension__c extenstion : scope) {
  32. //Send half time email to General Constructor
  33. 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 ){
  34. halfTimeToGwExtenstionList.add(extenstion);
  35. }
  36. //Send end time email to Customer and GW when expiration time passed
  37. if((extenstion.RecordType.DeveloperName ='Failure' || extenstion.RecordType.DeveloperName ='Handover_Failure' || extenstion.RecordType.DeveloperName ='Common_Failure')
  38. && extenstion.Today__c == extenstion.Half_Time_to_Fix_Defects_GW__c && extenstion.Status__ != 'Fixed' && extenstion.Status__c != 'Fixed by the contractor' ){
  39. endTimeExtenstionList.add(extenstion);
  40. }
  41. }
  42. if(halfTimeToGwExtenstionList.size() > 0){
  43. extenstionMapToSend.put(halfTimeTemplate,halfTimeToGwExtenstionList);
  44. }
  45. if(endTimeExtenstionList.size() > 0){
  46. extenstionMapToSend.put(endTimeCustomerTemplate,endTimeExtenstionList);
  47. extenstionMapToSend.put(endTimeToGW,endTimeExtenstionList);
  48. }
  49. try{
  50. //ResourceReservation.manextenstionMapToSend.put(ageReservationStatus(salesProcessesToUpdateQueue);
  51. ExtensionManager.sendExpirationReminderEmail(extenstionMapToSend);
  52. } catch(Exception e) {
  53. System.debug('Batch update failed. Details: '+e);
  54. }
  55. }
  56.  
  57. global void finish(Database.BatchableContext BC) {
  58.  
  59. }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement