Advertisement
Guest User

Untitled

a guest
Apr 16th, 2019
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 23.04 KB | None | 0 0
  1. /**
  2. * @purpose:   Represents the business logic as the deletion candidate.
  3. *
  4. * @author:    nilavan.manokaran@onivation.de
  5. *
  6. * @history:
  7. * version                   | author                          | changes
  8. * ====================================================================================
  9. * 0.1 (17.04.2018)          | nilavan.manokaran@onivation.de  | initial version
  10. * 0.2 (24.04.2018)          | julian.saarkamm@onivation.de     | continue to work
  11. * 0.3 (30.04.2017)      | christian.schwabe@onivation.de  | final version
  12. * 0.4 (11.07.2018)       | christian.schwabe@onivation.de  | added contructor with List<Id>
  13. * 0.5 (13.09.2018)       | johannes.heinrich@onivation.de  | +NumberOfRowsToDelete__c, Status__c, Operation__c;
  14. *                                 renamed labels; also logging besides the initial run
  15. * 0.6 (17.10.2018)       | selahattin.tuglu@onivation.de   | added new Criteria "Contact includes DOI" in
  16. *                                 Method "checkContactActivity()";
  17. * 0.7 (18.10.2018)       | johannes.heinrich@onivation.de  | load labels during tests; added params to helper constr
  18. * 0.8 (12.12.2018)       | yassin.oulghazi@onivation.de    | added if-statement that skips Account with Subtyp "WWN Partner"
  19. */
  20.  
  21. global class ContactDeletionAssessment implements Database.Batchable<sObject>, Database.Stateful, Schedulable {
  22.  
  23.  
  24.   public Integer tresholdValueDeleteCandidate;
  25.   public Boolean initialRunDeleteCandidate;
  26.  
  27.   private Id id;
  28.   private List<Id> listOfContactId;
  29.  
  30.   private Datetime startdate = Datetime.now();
  31.  
  32.   private Integer numberOfSuccessfullyDeletedRecords = 0;
  33.   private Integer numberOfNonDeletedRecords = 0;
  34.   private Integer numberOfSuccessfullyUpdatedRecords = 0;
  35.   private Integer numberOfNonUpdatedRecords = 0;
  36.   private String batchJobURL = '';
  37.  
  38.     private AsyncApexJob aaj;
  39.  
  40.   // Task
  41.   private Set<Id> setOfContactIdFromTask;
  42.   private Set<Id> setOfAccountIdFromTask;
  43.  
  44.   // Opportunity
  45.   private Set<Id> opportunityAccountIds;
  46.  
  47.   // Case
  48.   private Set<Id> setOfContactIdFromCase;
  49.   private Set<Id> setOfAccountIdFromCase;
  50.  
  51.   // Campaign
  52.   private Set<Id> campaignContactIds;
  53.  
  54.   // Nutzungsberechtigter
  55.   private Set<Id> authorizedUserIds;
  56.  
  57.   // Account
  58.   private Set<Id> setOfAccountIdWithTerritory;
  59.  
  60.  
  61.   // SAP Contract
  62.   private Set<Id> setOfAccountIdFromSapVertrag;
  63.  
  64.   // Contact to delete
  65.   private List<Id> setOfContactIdsToDelete;
  66.  
  67.   private Map<Id, Account> mapOfAccountById;
  68.  
  69.   global ContactDeletionAssessment(List<Id> listOfContactId){
  70.     this();
  71.     this.listOfContactId = listOfContactId;
  72.   }
  73.  
  74.   global ContactDeletionAssessment(Id id){
  75.     this();
  76.     this.id = id;
  77.   }
  78.  
  79.   global ContactDeletionAssessment() {
  80.     this.setOfContactIdFromTask = new Set<Id>();
  81.     this.setOfContactIdFromCase = new Set<Id>();
  82.     this.setOfAccountIdFromCase = new Set<Id>();
  83.     this.campaignContactIds = new Set<Id>();
  84.     this.authorizedUserIds = new Set<Id>();
  85.     this.setOfAccountIdFromSapVertrag = new Set<Id>();
  86.     this.setOfAccountIdFromTask = new Set<Id>();
  87.     this.opportunityAccountIds = new Set<Id>();
  88.     this.setOfContactIdsToDelete = new List<Id>();
  89.  
  90.     this.mapOfAccountById = new Map<Id, Account>();
  91.  
  92.     this.setOfAccountIdWithTerritory = new Set<Id>();
  93.  
  94.     if(this.tresholdValueDeleteCandidate == null){
  95.       this.tresholdValueDeleteCandidate = Integer.valueOf(System.Label.ContactThresholdValueDeleteCandidate);
  96.     }
  97.  
  98.     if(this.initialRunDeleteCandidate == null){
  99.       this.initialRunDeleteCandidate = Boolean.valueOf(System.Label.ContactInitialRunDeleteCandidate);
  100.     }
  101.   }
  102.  
  103.   global Database.QueryLocator start(Database.BatchableContext batchContext) {
  104.     this.aaj = [SELECT Id, Status, NumberOfErrors, ExtendedStatus, JobType, MethodName, JobItemsProcessed, TotalJobItems, CompletedDate, CreatedDate FROM AsyncApexJob WHERE Id = :batchContext.getJobId()];
  105.  
  106.     String query = 'SELECT ' +
  107.                         'Id, Name, CreatedDate, CONT_DeletionIndicator__c, CONT_DeletionIndicatorDate__c, CONT_Double_Opt_in_Mail_bestaetigt__c, ' +
  108.                         'AccountId, Account.Name, Account.Type, Account.ACCT_Subtyp__c, Account.Owner.Name, ' +
  109.                         'Account.ACCT_Vertriebsgebiet__c, Account.ACCT_Vertriebsgebiet__r.Name, Account.ACCT_Vertriebsgebiet__r.Owner.Name ' +
  110.                         'FROM Contact';
  111.  
  112.         if(String.isNotBlank(this.id)){
  113.           query += ' WHERE Id = \'' + this.id + '\'';
  114.         }
  115.  
  116.         if(this.listOfContactId != null && this.listOfContactId.size() > 0){
  117.           query += ' WHERE Id IN (\'' + String.join(this.listOfContactId, '\',\'') + '\')';
  118.         }
  119.  
  120.         //System.debug('>>>query: ' + query);
  121.     return Database.getQueryLocator(query);
  122.   }
  123.  
  124.   global void execute(SchedulableContext sc) {
  125.     ContactDeletionAssessment cda = new ContactDeletionAssessment();
  126.     Database.executeBatch(cda, 50);
  127.   }
  128.  
  129.      global void execute(Database.BatchableContext batchContext, List<Contact> scope) {
  130.  
  131.        // Contact List to Update Deletion Indicator
  132.     List<Contact> contactsToUpdate = new List<Contact>();
  133.     this.prepare(scope);
  134.  
  135.     List<ApexDebugLog__c> listOfApexDebugLog = new List<ApexDebugLog__c>();
  136.     for(Contact contact : scope) {
  137.       Boolean toBeDeleted = false;
  138.       Id accountId = contact.AccountId;
  139.       Account relatedAccount = null;
  140.  
  141.       if(String.isNotBlank(accountId) && this.mapOfAccountById.containsKey(accountId)){
  142.         relatedAccount = mapOfAccountById.get(contact.AccountId);
  143.       }
  144.  
  145.         //Kontakte unter Account mit Subtyp "WWN Partner" von der Verarbeitung ausnehmen.
  146.       if(relatedAccount != null) {
  147.         if(relatedAccount.ACCT_Subtyp__c != null && relatedAccount.ACCT_Subtyp__c == 'WWN Partner'){
  148.           continue;
  149.         }
  150.       }
  151.  
  152.       Boolean contactActivity = this.checkContactActivity(contact);
  153.       Boolean accountActivity = this.checkAccountActivity(relatedAccount);
  154.  
  155.       if(contactActivity) {
  156.         if(contact.CONT_DeletionIndicator__c){//Löschen eines vorh. Löschkennzeichen (CONT_DeletionIndicator__c) aufgrund einer aktiven Nutzung.
  157.           contact.CONT_DeletionIndicator__c = false;
  158.           contactsToUpdate.add(contact);
  159.         }
  160.       }
  161.      
  162.       //Keine Nutzung des Kontakts - Überprüfung der Account-Nutzung.
  163.       if(contactActivity == false && accountActivity) {
  164.         if(contact.CONT_DeletionIndicator__c == true) {//Der Kontakt ist als Löschkandidat vorgemerkt: Ja
  165.           if(contact.CONT_DeletionIndicatorDate__c < System.now().addMonths(-6)) {//Sechs (6) Monate lang wurde die Markierung des Löschkandidaten nicht verändert und weiterhin aktiv.
  166.             this.setOfContactIdsToDelete.add(contact.Id);
  167.             toBeDeleted = true;
  168.           }
  169.         } else{//Der Kontakt ist als Löschkandidat vorgemerkt: Nein
  170.           if(contact.CONT_DeletionIndicatorDate__c == null  || (contact.CONT_DeletionIndicatorDate__c != null && contact.CONT_DeletionIndicatorDate__c < System.now().addMonths(-12))) {
  171.             contact.CONT_DeletionIndicator__c = true;
  172.             contactsToUpdate.add(contact);
  173.           }
  174.         }
  175.       }
  176.  
  177.       //Keine Nutzung des Kontakts und keine Nutzung des Accounts
  178.       if(contactActivity == false && accountActivity == false) {
  179.         this.setOfContactIdsToDelete.add(contact.Id);
  180.         toBeDeleted = true;
  181.       }
  182.  
  183.       if(this.tresholdValueDeleteCandidate == 0 && toBeDeleted){//Create a detailed log for every to be deleted contact
  184.                 ApexDebugLog__c apexDebugLog = this.createApexDebugLog(contact);
  185.                 apexDebugLog.Notice__c = 'To be deleted';
  186.  
  187.                 if(this.initialRunDeleteCandidate){
  188.                   apexDebugLog = this.attachDetailedLog(apexDebugLog, contact);
  189.                 }
  190.  
  191.                 listOfApexDebugLog.add(apexDebugLog);
  192.       }
  193.     }
  194.    
  195.     insert listOfApexDebugLog;
  196.  
  197.     if (contactsToUpdate.size() > 0 && (this.setOfContactIdsToDelete.size() < this.tresholdValueDeleteCandidate)) {
  198.       this.updateList(contactsToUpdate, false);
  199.     }
  200.   }
  201.  
  202.  
  203.   global void finish(Database.BatchableContext batchContext) {
  204.     //"Master log" erstellen
  205.     this.aaj = [SELECT Id, Status, NumberOfErrors, ExtendedStatus, JobType, MethodName, JobItemsProcessed, TotalJobItems, CompletedDate, CreatedDate FROM AsyncApexJob WHERE Id = :batchContext.getJobId() limit: 1];
  206.     if(!Test.isRunningTest()){
  207.       String reportId = [SELECT Id FROM Report WHERE DeveloperName = 'ApexDebugLog'].id;
  208.       batchJobURL =  URL.getSalesforceBaseUrl().toExternalForm() + '/' + reportId +  '?pv0=' + batchContext.getJobId();
  209.     }
  210.     if(this.setOfContactIdsToDelete.size() > 0) {
  211.       if(this.setOfContactIdsToDelete.size() < this.tresholdValueDeleteCandidate) {
  212.               ContactDeletionAssessmentHelper cdah = new ContactDeletionAssessmentHelper(
  213.                                         this.setOfContactIdsToDelete,
  214.                                         batchContext.getJobId(),
  215.                                         this.aaj.CreatedDate,
  216.                                         this.numberOfSuccessfullyUpdatedRecords,
  217.                                         this.numberOfNonUpdatedRecords);
  218.               Database.executeBatch(cdah, 50);
  219.       } else {
  220.         ApexDebugLog__c masterAdl = new ApexDebugLog__c();
  221.         masterAdl.NumberOfRowsToDelete__c = setOfContactIdsToDelete.size();
  222.         masterAdl.Notice__c = 'Master';
  223.         masterAdl.Notice__c += '\nErreichen des Schwellwerts. Zu löschende Kontakte: '
  224.                     + masterAdl.NumberOfRowsToDelete__c + '. Schwellwert: '
  225.                     + this.tresholdValueDeleteCandidate + '.';
  226.         masterAdl.JobName__c = 'ContactDeletionAssessment';
  227.         masterAdl.Master__c = true;
  228.         masterAdl.BatchJobId18__c = this.aaj.Id;
  229.         masterAdl.JobStartDatetime__c = this.startdate;
  230.         masterAdl.JobEndDatetime__c =  this.aaj.CompletedDate;
  231.         masterAdl.NumberOfDeletedRows__c = this.numberOfSuccessfullyDeletedRecords;
  232.         masterAdl.NumberOfNonDeletedRows__c = this.numberOfNonDeletedRecords;
  233.         masterAdl.NumberOfUpdatedRows__c = this.numberOfSuccessfullyUpdatedRecords;
  234.         masterAdl.NumberOfNonUpdatedRows__c = this.numberOfNonUpdatedRecords;
  235.         masterAdl.ReportToLink__c = this.batchJobURL;
  236.         insert masterAdl;
  237.       }
  238.     } else {
  239.       ApexDebugLog__c masterAdl = new ApexDebugLog__c();
  240.       masterAdl.Notice__c = 'Master';
  241.       masterAdl.JobName__c = 'ContactDeletionAssessment';
  242.       masterAdl.Master__c = true;
  243.       masterAdl.BatchJobId18__c = this.aaj.Id;
  244.       masterAdl.JobStartDatetime__c = this.startdate;
  245.       masterAdl.JobEndDatetime__c =  this.aaj.CompletedDate;
  246.       masterAdl.NumberOfDeletedRows__c = this.numberOfSuccessfullyDeletedRecords;
  247.       masterAdl.NumberOfNonDeletedRows__c = this.numberOfNonDeletedRecords;
  248.       masterAdl.NumberOfUpdatedRows__c = this.numberOfSuccessfullyUpdatedRecords;
  249.       masterAdl.NumberOfNonUpdatedRows__c = this.numberOfNonUpdatedRecords;
  250.       masterAdl.ReportToLink__c = this.batchJobURL;
  251.       insert masterAdl;
  252.     }
  253.   }
  254.  
  255.   /**
  256.    * Dient zur Auslagerung der Abfragen hinsichtlich der Methoden checkAccountActivity und checkContactActivity.
  257.    *
  258.    * @param listOfContact
  259.    */
  260.   public void prepare(List<Contact> listOfContact){
  261.     List<Id> accountIds = new List<Id>();
  262.     List<Contact> scope = listOfContact;
  263.  
  264.     for(Contact contact : (List<Contact>) scope) {
  265.       if(String.isNotBlank(contact.AccountId)){
  266.         accountIds.add(contact.AccountId);
  267.       }
  268.     }
  269.  
  270.     this.mapOfAccountById = new Map<Id, Account>([SELECT Id, ACCT_Vertriebsgebiet__c, ACCT_Subtyp__c FROM Account WHERE Id = :accountIds]);
  271.  
  272.     List<Task> taskList = [SELECT Id, WhoId, WhatId, CreatedDate FROM Task WHERE CreatedDate > :System.now().addMonths(-38) AND (WhoId IN :scope OR WhatId IN :accountIds) AND IsDeleted = false ALL ROWS];
  273.     for(Task task : taskList) {
  274.       if( String.isNotBlank(task.whoId)){
  275.         this.setOfContactIdFromTask.add(task.whoId);
  276.       }
  277.  
  278.       if(String.isNotBlank(task.whatId)){
  279.         this.setOfAccountIdFromTask.add(task.whatId);
  280.       }
  281.     }
  282.  
  283.     //Map<Id, Opportunity> mapOfOpportunityById = new Map<Id, Opportunity>([SELECT Id, AccountId FROM Opportunity WHERE CreatedDate > :System.now().addMonths(-38) AND (AccountId = :accountIds OR OPP_Abw_ReEmpf_Kontaktname__c IN :scope OR OPP_Kontaktname__c IN :scope OR OPP_Rechnung_Kontaktname__c IN :scope)]);
  284.     for(Opportunity opportunity : [SELECT Id, AccountId
  285.                     FROM Opportunity
  286.                     WHERE CreatedDate > :System.now().addMonths(-38) AND
  287.                       (AccountId = :accountIds OR
  288.                       OPP_Abw_ReEmpf_Kontaktname__c IN :scope OR
  289.                       OPP_Kontaktname__c IN :scope OR
  290.                       OPP_Rechnung_Kontaktname__c IN :scope)]) {
  291.       //Opportunity opportunity = mapOfOpportunityById.get(opportunityId);
  292.  
  293.       if(String.isNotBlank(opportunity.AccountId)){
  294.         this.opportunityAccountIds.add(opportunity.AccountId);
  295.       }        
  296.     }
  297.  
  298.     /*List<Case> caseList =   [SELECT
  299.                   Id,
  300.                   ContactId,
  301.                   AccountId
  302.                 FROM
  303.                   Case
  304.                 WHERE
  305.                   CreatedDate > :System.now().addMonths(-38) AND
  306.                   (ContactId IN :scope OR AccountId IN :accountIds)
  307.                 ];*/
  308.     for(Case caseObj : [SELECT Id, ContactId, AccountId
  309.               FROM
  310.                 Case
  311.               WHERE
  312.                 CreatedDate > :System.now().addMonths(-38) AND
  313.                 (ContactId IN :scope OR AccountId IN :accountIds)
  314.               ]) {
  315.       If(String.isNotBlank(caseObj.ContactId)){
  316.         this.setOfContactIdFromCase.add(caseObj.ContactId);
  317.       }
  318.  
  319.       if(String.isNotBlank(caseObj.AccountId)){
  320.         this.setOfAccountIdFromCase.add(caseObj.AccountId);
  321.       }
  322.     }
  323.  
  324.     for(CampaignMember campaignMember : [SELECT Id, CampaignId, ContactId
  325.                       FROM
  326.                         CampaignMember
  327.                       WHERE
  328.                         ContactId IN :scope AND
  329.                         CreatedDate > :System.now().addMonths(-38)
  330.                       ]) {
  331.       this.campaignContactIds.add(campaignMember.ContactId);
  332.     }
  333.  
  334.     for(Nutzungsberechtiger__c authorizedUser : [SELECT Id, UID_User__c
  335.                           FROM Nutzungsberechtiger__c
  336.                           WHERE
  337.                             UID_Status__c = 'Aktiv' AND
  338.                             CreatedDate > :System.now().addMonths(-38) AND
  339.                             UID_User__c IN :scope
  340.                           ]) {
  341.       this.authorizedUserIds.add(authorizedUser.UID_User__c);
  342.     }
  343.  
  344.     //List<SAP_Vertrag__c> sapContractList = new List<SAP_Vertrag__c>([SELECT Id, SAPV_Account__c FROM SAP_Vertrag__c WHERE CreatedDate > :System.now().addMonths(-38) AND SAPV_Account__c = :accountIds]);
  345.     for(SAP_Vertrag__c sapVertrag : [SELECT Id, SAPV_Account__c
  346.                       FROM SAP_Vertrag__c
  347.                       WHERE CreatedDate > :System.now().addMonths(-38)
  348.                       AND SAPV_Account__c = :accountIds]) {
  349.       if(String.isNotBlank(sapVertrag.SAPV_Account__c)){
  350.         this.setOfAccountIdFromSapVertrag.add(sapVertrag.SAPV_Account__c);
  351.       }
  352.     }
  353.  
  354.     for(Id accountId : this.mapOfAccountById.keySet()){
  355.       Account account = this.mapOfAccountById.get(accountId);
  356.  
  357.       if(String.isNotBlank(account.ACCT_Vertriebsgebiet__c)){
  358.         this.setOfAccountIdWithTerritory.add(accountId);
  359.       }
  360.     }
  361.   }
  362.  
  363.   private void updateList(Contact[] contactsToUpdate, Boolean allOrNone) {
  364.         List<Database.SaveResult> saveResult =  Database.update(contactsToUpdate, allOrNone);
  365.         List<ApexDebugLog__c> listOfApexDebugLog = new List<ApexDebugLog__c>();
  366.         Integer i = 0;
  367.    
  368.         for (Database.saveResult result : saveResult) {
  369.       Contact contact = contactsToUpdate.get(i);
  370.  
  371.             if (result.isSuccess()) {
  372.                 this.numberOfSuccessfullyUpdatedRecords++;
  373.  
  374.                 ApexDebugLog__c adl = this.createApexDebugLog(contact);
  375.               adl.Notice__c = 'SUCCESS -- UPDATED';
  376.                 adl.Operation__c = 'Update';
  377.                 adl.Status__c = 'Info';
  378.  
  379.               if(this.initialRunDeleteCandidate){
  380.                 adl = this.attachDetailedLog(adl, contactsToUpdate.get(i));
  381.               }
  382.  
  383.               listOfApexDebugLog.add(adl);
  384.             } else {
  385.                 this.numberOfNonUpdatedRecords++;
  386.  
  387.                 for(Database.Error err : result.getErrors()) {
  388.                     //Id id15 = String.valueOf(contactsToUpdate.get(i).Id).left(15);
  389.           ApexDebugLog__c adl = this.createApexDebugLog(contact,
  390.                                   err.getFields(),
  391.                                   err.getMessage(),
  392.                                   err.getStatusCode());
  393.                   adl.Notice__c = 'FAILURE -- UPDATED';
  394.                     adl.Operation__c = 'Update';
  395.                     adl.Status__c = 'Error';
  396.  
  397.                   if(this.initialRunDeleteCandidate){
  398.                     adl = this.attachDetailedLog(adl, contact);
  399.                   }
  400.  
  401.                     listOfApexDebugLog.add(adl);
  402.                 }
  403.             }
  404.  
  405.             i++;
  406.         }
  407.        
  408.         insert listOfApexDebugLog;
  409.     }
  410.  
  411.   // Check First Criteria
  412.   private Boolean checkContactActivity(Contact contact) {
  413.     if(contact.CreatedDate > System.now().addMonths(-26)) { // Check Contact Date
  414.       return true;
  415.     }
  416.     else if(contact.CONT_Double_Opt_in_Mail_bestaetigt__c) {    
  417.             // Returns true when Lead includes DOI
  418.             return true;
  419.         }
  420.     else if(this.checkTasks(contact)) {
  421.       return true;
  422.     }
  423.     /*else if(this.checkOpportunityContactRole(contact)) {
  424.       return true;
  425.     }*/
  426.     else if(this.checkCases(contact)) {
  427.       return true;
  428.     }
  429.     else if(this.checkCampaigns(contact)) {
  430.       return true;
  431.     } else if(this.checkAuthorizedUsers(contact)){
  432.       return true;
  433.  
  434.     } else {
  435.       return false;
  436.     }
  437.   }
  438.  
  439.   // Check second Criteria
  440.   public Boolean checkAccountActivity(Account account) {
  441.     //System.debug('>>>account: ' + account);
  442.     if(account == null){
  443.       return false;
  444.     }
  445.     else if(this.checkSapVertrag(account)) {
  446.       //System.debug('>>>true.');
  447.       return true;
  448.     }
  449.     else if(this.checkTerritory(account)) {
  450.       //System.debug('>>>true.');
  451.       return true;
  452.     }
  453.     else if(this.checkTaskAccount(account)) {
  454.       //System.debug('>>>true.');
  455.       return true;
  456.     }
  457.     else if(this.checkOpportunitiesAccount(account)) {
  458.       //System.debug('>>>true.');
  459.       return true;
  460.     }
  461.     else if(this.checkCaseAccount(account)) {
  462.       //System.debug('>>>true.');
  463.       return true;
  464.     }
  465.     else  {
  466.       //System.debug('>>>false.');
  467.       return false;
  468.     }
  469.   }
  470.  
  471.  
  472.  
  473.   // --------------------------------------
  474.   //Second Criteria
  475.   private Boolean checkCaseAccount(Account account) {    
  476.     if(this.setOfAccountIdFromCase.contains(account.Id)) {
  477.       //System.debug('>>>true.');
  478.       return true;
  479.     } else {
  480.       //System.debug('>>>false.');
  481.       return false;
  482.     }
  483.   }
  484.   private Boolean checkOpportunitiesAccount(Account account) {
  485.     if(this.opportunityAccountIds.contains(account.Id)) {
  486.       //System.debug('>>>true.');
  487.       return true;
  488.     } else {
  489.       //System.debug('>>>false.');
  490.       return false;
  491.     }
  492.   }
  493.  
  494.   private Boolean checkTaskAccount(Account account) {
  495.     if(this.setOfAccountIdFromTask.contains(account.Id)) {
  496.       //System.debug('>>>true.');
  497.       return true;
  498.     } else {
  499.       //System.debug('>>>false.');
  500.       return false;
  501.     }
  502.   }
  503.  
  504.   private Boolean checkSapVertrag(Account account) {
  505.     if(this.setOfAccountIdFromSapVertrag.contains(account.Id)) {
  506.       //System.debug('>>>true.');
  507.       return true;
  508.     } else {
  509.       //System.debug('>>>false.');
  510.       return false;
  511.     }
  512.   }
  513.  
  514.   private Boolean checkTerritory(Account account) {
  515.     if(this.setOfAccountIdWithTerritory.contains(account.Id)) {
  516.       //System.debug('>>>true.');
  517.       return true;
  518.     } else {
  519.       //System.debug('>>>false.');
  520.       return false;
  521.     }
  522.   }
  523.  
  524.   // --------------------------------------
  525.   // First Criteria
  526.   private Boolean checkTasks(Contact contact) {
  527.     if(this.setOfContactIdFromTask.contains(contact.Id)) {
  528.       //System.debug('>>>true.');
  529.       return true;
  530.     } else {
  531.       //System.debug('>>>false.');
  532.       return false;
  533.     }
  534.   }
  535.  
  536. /*  private Boolean checkOpportunityContactRole(Contact contact) {
  537.     if(this.opportunityContactIds.contains(contact.Id)) {
  538.       return true;
  539.     } else {
  540.       return false;
  541.     }
  542.   }*/
  543.  
  544.   private Boolean checkCases(Contact contact) {
  545.     if(this.setOfContactIdFromCase.contains(contact.Id)) {
  546.       //System.debug('>>>true.');
  547.       return true;
  548.     } else {
  549.       //System.debug('>>>false.');
  550.       return false;
  551.     }
  552.   }
  553.  
  554.   private Boolean checkCampaigns(Contact contact) {
  555.     if(this.campaignContactIds.contains(contact.Id)) {
  556.       //System.debug('>>>true.');
  557.       return true;
  558.     } else {
  559.       //System.debug('>>>false.');
  560.       return false;
  561.     }
  562.   }
  563.  
  564.   private Boolean checkAuthorizedUsers(Contact contact) {
  565.     if(this.authorizedUserIds.contains(contact.Id)) {
  566.       //System.debug('>>>true.');
  567.       return true;
  568.     } else {
  569.       //System.debug('>>>false.');
  570.       return false;
  571.     }
  572.   }
  573.  
  574.   private ApexDebugLog__c createApexDebugLog(Contact contact, List<String> errorFields, String errorMessage, StatusCode statusCode){
  575.         ApexDebugLog__c adl = new ApexDebugLog__c();
  576.         Id id15 = String.valueOf(contact.Id).left(15);
  577.  
  578.         adl.BatchJobId18__c = this.aaj.Id;
  579.         adl.JobName__c = 'ContactDeletionAssessment';        
  580.         adl.Id15__c = id15;                        
  581.         adl.Fields__c = String.join(errorFields, ',');
  582.         adl.Notice__c = errorMessage;
  583.         adl.Statuscode__c = String.valueOf(statusCode);
  584.         return adl;
  585.   }
  586.  
  587.   private ApexDebugLog__c createApexDebugLog(Contact contact){
  588.         ApexDebugLog__c adl = new ApexDebugLog__c();
  589.         Id id15 = String.valueOf(contact.Id).left(15);
  590.  
  591.         adl.BatchJobId18__c = this.aaj.Id;
  592.         adl.JobName__c = 'ContactDeletionAssessment';
  593.         adl.Id15__c = id15;
  594.         return adl;
  595.   }
  596.  
  597.   private ApexDebugLog__c attachDetailedLog(ApexDebugLog__c adl, Contact contact){
  598.     adl.Notice__c += '\nKontaktname: '  + contact.Name + '\n';
  599.     adl.Notice__c += 'Account-Id: '  + contact.AccountId + '\n';
  600.     adl.Notice__c += 'Account-Name: '  + contact.Account.Name + '\n';
  601.     adl.Notice__c += 'Account-Typ: '  + contact.Account.Type + '\n';
  602.     adl.Notice__c += 'Account-Subtyp: '  + contact.Account.ACCT_Subtyp__c + '\n';
  603.     adl.Notice__c += 'Name des Account-Inhabers: '  + contact.Account.Owner.Name + '\n';
  604.     adl.Notice__c += 'Vertriebsgebiet: '  + contact.Account.ACCT_Vertriebsgebiet__r.Name + '\n';
  605.     adl.Notice__c += 'Name des Vertriebsgebiet-Inhabers: '  + contact.Account.ACCT_Vertriebsgebiet__r.Owner.Name;
  606.     return adl;
  607.   }
  608. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement