• Nagendra Babu 55
  • NEWBIE
  • 5 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 3
    Replies
global class ReportIssueContactAssociationBatch implements Database.Batchable<sObject> {
    
    global Database.QueryLocator start(Database.BatchableContext bc){
         return Database.getQueryLocator([SELECT Id, Contact__c, Email__c FROM Issue__c WHERE Contact__c = NULL]);  
    }
    
    global void execute(Database.BatchableContext bc, List<sObject> scope){
        // loop through all Issue records and collect email addresses
        // Query Contacts based on Email Addresses
        // Create a Map of Email -- Contact
        
        Set<String> allEmails = new Set<String>();
        for(sObject so : scope){
            Issue__c issue = (Issue__c)so;
            allEmails.add(issue.Email__c);
        }
        
        Map<String, String> contactEmailContactIdMap = new Map<String, String>();
        for(Contact c : [SELECT id, Email FROM Contact WHERE EMail IN :allEmails]){
            contactEmailContactIdMap.put(c.Email, c.Id);
        }
        
        for(sObject so : scope){
            Issue__c issue = (Issue__c)so;
            issue.Contact__c = contactEmailContactIdMap.get(issue.Email__c);
        }
        Database.update(scope);
    }
    
    global void finish(Database.BatchableContext bc){
        
    }
    

}

 
global class ReportIssueContactAssociationBatch implements Database.Batchable<sObject> {
    
    global Database.QueryLocator start(Database.BatchableContext bc){
         return Database.getQueryLocator([SELECT Id, Contact__c, Email__c FROM Issue__c WHERE Contact__c = NULL]);  
    }
    
    global void execute(Database.BatchableContext bc, List<sObject> scope){
        // loop through all Issue records and collect email addresses
        // Query Contacts based on Email Addresses
        // Create a Map of Email -- Contact
        
        Set<String> allEmails = new Set<String>();
        for(sObject so : scope){
            Issue__c issue = (Issue__c)so;
            allEmails.add(issue.Email__c);
        }
        
        Map<String, String> contactEmailContactIdMap = new Map<String, String>();
        for(Contact c : [SELECT id, Email FROM Contact WHERE EMail IN :allEmails]){
            contactEmailContactIdMap.put(c.Email, c.Id);
        }
        
        for(sObject so : scope){
            Issue__c issue = (Issue__c)so;
            issue.Contact__c = contactEmailContactIdMap.get(issue.Email__c);
        }
        Database.update(scope);
    }
    
    global void finish(Database.BatchableContext bc){
        
    }
    

}

 
global class ReportIssueContactAssociationBatch implements Database.Batchable<sObject> {
    
    global Database.QueryLocator start(Database.BatchableContext bc){
         return Database.getQueryLocator([SELECT Id, Contact__c, Email__c FROM Issue__c WHERE Contact__c = NULL]);  
    }
    
    global void execute(Database.BatchableContext bc, List<sObject> scope){
        // loop through all Issue records and collect email addresses
        // Query Contacts based on Email Addresses
        // Create a Map of Email -- Contact
        
        Set<String> allEmails = new Set<String>();
        for(sObject so : scope){
            Issue__c issue = (Issue__c)so;
            allEmails.add(issue.Email__c);
        }
        
        Map<String, String> contactEmailContactIdMap = new Map<String, String>();
        for(Contact c : [SELECT id, Email FROM Contact WHERE EMail IN :allEmails]){
            contactEmailContactIdMap.put(c.Email, c.Id);
        }
        
        for(sObject so : scope){
            Issue__c issue = (Issue__c)so;
            issue.Contact__c = contactEmailContactIdMap.get(issue.Email__c);
        }
        Database.update(scope);
    }
    
    global void finish(Database.BatchableContext bc){
        
    }
    

}