Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.15 KB | None | 0 0
  1. /*
  2. Method Name: Start
  3. Description: This method is used to collect the TAC records ready for deletion.
  4. */
  5. global Database.QueryLocator Start(Database.BatchableContext info)
  6. {
  7. // fetch TAC records ready for removal.
  8.  
  9. String Query = 'SELECT ABI_SFA_Account_Removal__c,ABI_SFA_Account__c,ABI_SFA_RecordID__c,ABI_SFA_SHAREID__c, ABI_SFA_Type__c,ABI_SFA_User__c,ABI_SFA_Valid_Till__c,CreatedById,CreatedDate,CurrencyIsoCode,Id,IsDeleted,LastModifiedById,LastModifiedDate,Name,OwnerId,SystemModstamp FROM ABI_SFA_TerritoryAccountChange__c WHERE ABI_SFA_Account__r.name like '%Europromotion%' LIMIT 50000';
  10.  
  11. return Database.getQueryLocator(query);
  12. }
  13.  
  14. /*
  15. Method Name: Execute
  16. Description: This method is used to process the TAC records that are passed from Start method.
  17. */
  18. global void Execute(Database.BatchableContext info, List<ABI_SFA_TerritoryAccountChange__c> tacList)
  19. {
  20. if(tacList!=Null && tacList!=Empty){
  21. System.debug('@@@inside IF block');
  22. try {
  23. System.debug('@@@inside TRY block');
  24. Database.DeleteResult[] TAC_Dels = Database.delete(tacList);
  25. }
  26. catch (DmlException e) {
  27. System.debug('@@@ The following exception has occurred: ' + e.getMessage());
  28. ApexPages.addMessage(myMsg);
  29. ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR,<strong>string.valueof(e)</strong>);
  30. }
  31. }
  32. }
  33.  
  34.  
  35. /*
  36. Method Name: Finish
  37. Description: This method is used to notify all relevant stakeholders via Email.
  38. */
  39. global void Finish(Database.BatchableContext info){
  40.  
  41. String Email;
  42. List<ID> tacERId = new List<ID>();
  43. public void SendEmail() {
  44. for(TACEmailRecipients__c tacER: TACEmailRecipients__c.getAll().values());{
  45. tacERId.add(tacER.Id);
  46. }
  47.  
  48. EmailTemplate et=[Select id from EmailTemplate where name = 'TAC_Notification' limit 1];
  49.  
  50. Messaging.MassEmailMessage mail = new Messaging.MassEmailMessage();
  51. mail.setTargetObjectIds(tacERId);
  52. mail.setSenderDisplayName('Acenture Support Team');
  53. mail.setTemplateId(et.id);
  54. Messaging.sendEmail(new Messaging.MassEmailMessage[] { mail });
  55.  
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement