• Isha Saxena 9
  • NEWBIE
  • 0 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 5
    Replies
global class Batch_Account_Manager_change_update implements Database.Batchable<sobject>
{
      List<Account_Allocation_Rules__c> acc_rule = new List<Account_Allocation_Rules__c>();
      string rid = [SELECT id from RecordType where Name ='Tyro Customer'].Id;
      string dynamicQuery = null;
      boolean flag = false;
      Integer num = 0;
      string sg = null;
      Set<ID> setAccRuleId = new Set<ID>();
      List<Account> upacc = new List<Account>();
      List<Account> acct = new List<Account>();
      Set<string> paramlist = new Set<string>();
      Map<String,account> accmap = new map<String,account>();
      
     global Database.QueryLocator start(Database.BatchableContext bc)
    {
        return Database.getQueryLocator('Select Id,Name,RecordType.Id,Active__c,Account_Manager__c,Active_User__c,Industry__c,Integration_Product__c,Lookup_Parameters__c,Rule_Allocation_Name__c,Segment__c from Account_Allocation_Rules__c where LastModifiedDate = Today');
        
    }
    global void execute(Database.BatchableContext bc,List<Account_Allocation_Rules__c> sobj)
    {
             System.debug('Account Allocation Rule'+sobj);
        
           for(Account_Allocation_Rules__c alc : sobj) 
           {
            if(alc.Lookup_Parameters__c != null)
            {
                    paramlist.add(alc.Lookup_Parameters__c);
            }

           }
          acct = [Select Id,OwnerId,Segment__c,Account_Allocation_Parameters__c,Corporate_Group__c from Account where  RecordType.Id =: rid and Corporate_Group__c = null and Key_Account__c = false and Merchant_Group_Member__c = 0 and Account_Allocation_Parameters__c in : paramlist];    
          //acct = Database.query(dynamicQuery);
         
           if(acct.size()>0)
           {        
              for (Account at : acct)
              {
                   accmap.put(at.id, at);
              }
            }

          System.debug('#######Account Map'+accmap);
          
                  System.debug('testing time');        
                    
                    for(account act : accmap.values())
                     {
                        for (Account_Allocation_Rules__c alc : sobj) 
                       {
                           
                           System.debug('########DrillDown');
                           if (act.Account_Allocation_Parameters__c == alc.Lookup_Parameters__c)
                            {
                                 System.debug('########DrillDown111111');
                                  system.debug(LoggingLevel.INFO, alc.Lookup_Parameters__c + ' exist');
                                  System.debug('Account Owner Id####'+act.OwnerId);
                                  System.debug('Allocation Account Manager'+alc.Account_Manager__c);
                                  act.OwnerId = alc.Account_Manager__c ;
                                  upacc.add(act);
             
                              }
                              else
                              {
                                      system.debug(LoggingLevel.INFO, alc.Lookup_Parameters__c + ' does not exist');
                              }
                 }
          }        

         System.debug('Updated Account List*******'+upacc);
         
         
          
                 
        
    }
    
    global void finish(Database.BatchableContext bc)
    {
           
            update upacc;
    }

}
global class Batch_Account_Manager_change_update implements Database.Batchable<sobject>
{
      List<Account_Allocation_Rules__c> acc_rule = new List<Account_Allocation_Rules__c>();
      string rid = [SELECT id from RecordType where Name ='Tyro Customer'].Id;
      string dynamicQuery = null;
      boolean flag = false;
      Integer num = 0;
      string sg = null;
      Set<ID> setAccRuleId = new Set<ID>();
      List<Account> upacc = new List<Account>();
      List<Account> acct = new List<Account>();
      Set<string> paramlist = new Set<string>();
      Map<String,account> accmap = new map<String,account>();
      
     global Database.QueryLocator start(Database.BatchableContext bc)
    {
        return Database.getQueryLocator('Select Id,Name,RecordType.Id,Active__c,Account_Manager__c,Active_User__c,Industry__c,Integration_Product__c,Lookup_Parameters__c,Rule_Allocation_Name__c,Segment__c from Account_Allocation_Rules__c where LastModifiedDate = Today');
        
    }
    global void execute(Database.BatchableContext bc,List<Account_Allocation_Rules__c> sobj)
    {
             System.debug('Account Allocation Rule'+sobj);
        
           for(Account_Allocation_Rules__c alc : sobj) 
           {
            if(alc.Lookup_Parameters__c != null)
            {
                    paramlist.add(alc.Lookup_Parameters__c);
            }

           }
          acct = [Select Id,OwnerId,Segment__c,Account_Allocation_Parameters__c,Corporate_Group__c from Account where  RecordType.Id =: rid and Corporate_Group__c = null and Key_Account__c = false and Merchant_Group_Member__c = 0 and Account_Allocation_Parameters__c in : paramlist];    
          //acct = Database.query(dynamicQuery);
         
           if(acct.size()>0)
           {        
              for (Account at : acct)
              {
                   accmap.put(at.id, at);
              }
            }

          System.debug('#######Account Map'+accmap);
          
                  System.debug('testing time');        
                    
                    for(account act : accmap.values())
                     {
                        for (Account_Allocation_Rules__c alc : sobj) 
                       {
                           
                           System.debug('########DrillDown');
                           if (act.Account_Allocation_Parameters__c == alc.Lookup_Parameters__c)
                            {
                                 System.debug('########DrillDown111111');
                                  system.debug(LoggingLevel.INFO, alc.Lookup_Parameters__c + ' exist');
                                  System.debug('Account Owner Id####'+act.OwnerId);
                                  System.debug('Allocation Account Manager'+alc.Account_Manager__c);
                                  act.OwnerId = alc.Account_Manager__c ;
                                  upacc.add(act);
             
                              }
                              else
                              {
                                      system.debug(LoggingLevel.INFO, alc.Lookup_Parameters__c + ' does not exist');
                              }
                 }
          }        

         System.debug('Updated Account List*******'+upacc);
         
         
          
                 
        
    }
    
    global void finish(Database.BatchableContext bc)
    {
           
            update upacc;
    }

}