+ Start a Discussion
golla Anithagolla Anitha 

When duplicates are found on Leads, then the user of profile ‘FCL-Sales’ should be able to merge leads only of record type ‘FCL-Sales’. Schedule it every 2 hrs.

When duplicates are found on Leads, then the user of profile ‘FCL-Sales’ should be able to  merge leads only of record type ‘FCL-Sales’. Schedule it every 2 hrs.  
 \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
global class leaduserprofile implements 
  Database.Batchable<sObject>, Database.Stateful {
     global Integer recordsProcessed = 0;
       global Database.QueryLocator start(Database.BatchableContext bc)
       {
           return database.getQueryLocator(' Select email,  RecordType.Name,count(id) FROM lead WHERE recordtypeid in (Select Id From RecordType where sobjecttype in: lead and DeveloperName IN : fcl_service)GROUP BY email,RecordType.Name ');     
       }
      public void execute(database.BatchableContext bc,List<lead> scope)
      {
         List<lead> ld=new list<lead>();
          system.debug('scope'+scope);
          map<string,List<lead>> mapping=new map<string,List<lead>>();
          for(lead ld1:scope)
          {
              ld.add(ld1);
              system.debug('ld'+ld);
              mapping.put(ld1.Email,ld);
              system.debug('mapping'+mapping);
              for(integer i=mapping.size();i>0;i--)
              {
                 merge ld1 ld[i] ;
                  system.debug('ld1'+ld1);
                  recordsProcessed = recordsProcessed + 1;
     }}
      update ld;
      }
       public void finish(database.BatchableContext bc)
       {
             System.debug(recordsProcessed + ' records processed. Shazam!');
        AsyncApexJob job = [SELECT Id, Status, NumberOfErrors,
            JobItemsProcessed,
            TotalJobItems, CreatedBy.Email
            FROM AsyncApexJob
            WHERE Id = :bc.getJobId()];
           
       }
  }
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
can you please help on this
PriyaPriya (Salesforce Developers) 

Hi Golla,

May I know what is the error you are getting ?

Regards,

Priya Ranjan

golla Anithagolla Anitha
soql was not fetching the values in back end it was working
golla Anithagolla Anitha
check once the code also please
golla Anithagolla Anitha
22:30:30:042 EXCEPTION_THROWN [6]|System.QueryException: Aggregate query does not support queryMore(), use LIMIT to restrict the results to a single batch