• golla Anitha
  • NEWBIE
  • 10 Points
  • Member since 2021

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 5
    Replies
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
Create a custom field called 'Count of Cases' on Contact record. This should contain the count of associated cases on the Contact. In the event of deletion of a Case, this count field should be updated appropriately on the Contact. Also, Test class should be written. 
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
public class contactcase {
    public static void contactcasemethod(List<case> lstcase)
    {
        List<id> lstid=new List<id>();
        for(case c:lstcase)
    {
        lstid.add(c.ContactId);
         system.debug('lstid'+lstid);
        
    }
        integer noOfRecInCase=lstcase.size();
        system.debug('noOfRecInCase'+noOfRecInCase);
        //fetch contact record to update if exists
      List <contact> replica=[select id,Count_of_Cases__c from contact where id in :lstid ];
        system.debug('fetch contact record to update if exists'+replica);
        if(replica.size()>0)
        {
        List<integer> casecount=[SELECT count(id) FROM case WHERE contactid in:replica];
        
        //logic for inserting new case, update contact count
         
        for(contact replica3:replica)
       {
           if(casecount[0]>0 || casecount[0]!=null)
           {
       replica3.Count_of_Cases__c=casecount[0]+noOfRecInCase;
           system.debug('logic for inserting new case, update contact count'+replica3);
           }
        else{
            replica3.Count_of_Cases__c=noOfRecInCase;
             system.debug('logic for inserting new case, update contact count1'+replica3);
        }
       }
        }
        update replica;
    }
}
   /* public static void contactcasemethod1(List<case> lstcase1)
    {
        List<id> lstid1=new List<id>();
        for(case c1:lstcase1)
    {
        lstid1.add(c1.ContactId);
         system.debug('lstid'+lstid1);
        
    }
        integer noOfRecInCase1=lstcase1.size();
        //fetch contact record to update if exists
      List <contact> replic=[select id,Count_of_Cases__c from contact where id in :lstid1 ];
        system.debug('fetch contact record to update if exists'+replic);
        if(replic.size()>0)
        {
        List<case> casecount=[SELECT Origin, Subject, status, ContactId FROM case WHERE contactid in:replic];
        system.debug('casecount'+casecount.size());
        //logic for inserting new case, update contact count
        for(contact replica3:replic)
       {
           if(casecount.size()>0 || casecount.size()!=null)
           {
       replica3.Count_of_Cases__c=casecount.size()-noOfRecInCase1;
           system.debug('logic for inserting new case, update contact count'+replica3);
           }
        else{
            replica3.Count_of_Cases__c=noOfRecInCase1;
             system.debug('logic for inserting new case, update contact count1'+replica3);
        }
       }
        }
        update replic;
    }
}*/
error was like
Illegal assignment from List<AggregateResult> to List<Integer>
@istest
public class Accountupdatetest {
    @testsetup
    static void Fieldvalues()
    {
        Account accountList=new Account(name='bargavi',BillingPostalCode='56789');
         insert accountList ;
        Address__c adds=new Address__c(zip_code__c='56789',State_City__c='karntaka',Country__c='india',Street__c='dangal');
         insert adds;
    }
    @istest
   static void test1()
    {
         Account acc2=[select name,BillingPostalCode,BillingCity,BillingCountry,BillingStreet from Account ];
       // Address__C adds1=[select Street__c,Zip_code__c,State_City__c,Country__c from Address__C];

         test.startTest(); 
          acc2.BillingPostalCode='56789';
        try{
         update acc2; 
        }
        catch(DmlException exp)
        {
            system.assert(exp.getMessage().contains('no address zipcode matched to the billing postal code'));
        }
    
       test.stopTest(); 
    }
}
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
public class Accountupdate {
public static void Mymethod(List<Account> acc)
          {
//List<Account> addition=new List<Account>();
           set<String> Collectstring=new set<String>();
                 for(Account collectzipcode:acc)
                     {
                           Collectstring.add(collectzipcode.BillingPostalCode);
                           system.debug(' collect All the Zip code ids'+Collectstring);
                      }
            List<Address__c> fetch=[select Street__c,Zip_code__c,State_City__c,Country__c  from Address__c where Zip_code__c in:Collectstring];
             system.debug(+fetch);
            Map<String,Address__c> maping=new Map<String,Address__c>();
                for(Address__c edit:fetch)
                    {
                       maping.put(edit.Zip_code__c,edit);
                        system.debug('maping'+maping);
                     }
                      for(Account acc1:acc)
                             {
                                 List<Address__c> lstAdd=new List<Address__c>();
                               Address__c lastoutput=maping.get(acc1.BillingPostalCode);
                                 lstadd.add(lastoutput);
                                 system.debug('lastoutput'+lastoutput);
                                        if(lstadd.size()<>null)
                                          {
                                              acc1.BillingCity=lastoutput.State_City__c;
                                               acc1.BillingCountry=lastoutput.Country__c;
                                               acc1.BillingStreet=lastoutput.Street__c;
                                           }
                           else
                           {
                                     acc1.adderror('no address zipcode matched to the billing postal code');
                           }

                              }
            }
}
///////////////////////////////////////////////////////////////////////////////////////////////////////
error
//////////////////////
System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, addressontrigger: execution of BeforeInsert

caused by: System.NullPointerException: Attempt to de-reference a null object

Class.Accountupdate.Mymethod: line 27, column 1
Trigger.addressontrigger: line 3, column 1: []
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
Create a custom field called 'Count of Cases' on Contact record. This should contain the count of associated cases on the Contact. In the event of deletion of a Case, this count field should be updated appropriately on the Contact. Also, Test class should be written. 
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
public class contactcase {
    public static void contactcasemethod(List<case> lstcase)
    {
        List<id> lstid=new List<id>();
        for(case c:lstcase)
    {
        lstid.add(c.ContactId);
         system.debug('lstid'+lstid);
        
    }
        integer noOfRecInCase=lstcase.size();
        system.debug('noOfRecInCase'+noOfRecInCase);
        //fetch contact record to update if exists
      List <contact> replica=[select id,Count_of_Cases__c from contact where id in :lstid ];
        system.debug('fetch contact record to update if exists'+replica);
        if(replica.size()>0)
        {
        List<integer> casecount=[SELECT count(id) FROM case WHERE contactid in:replica];
        
        //logic for inserting new case, update contact count
         
        for(contact replica3:replica)
       {
           if(casecount[0]>0 || casecount[0]!=null)
           {
       replica3.Count_of_Cases__c=casecount[0]+noOfRecInCase;
           system.debug('logic for inserting new case, update contact count'+replica3);
           }
        else{
            replica3.Count_of_Cases__c=noOfRecInCase;
             system.debug('logic for inserting new case, update contact count1'+replica3);
        }
       }
        }
        update replica;
    }
}
   /* public static void contactcasemethod1(List<case> lstcase1)
    {
        List<id> lstid1=new List<id>();
        for(case c1:lstcase1)
    {
        lstid1.add(c1.ContactId);
         system.debug('lstid'+lstid1);
        
    }
        integer noOfRecInCase1=lstcase1.size();
        //fetch contact record to update if exists
      List <contact> replic=[select id,Count_of_Cases__c from contact where id in :lstid1 ];
        system.debug('fetch contact record to update if exists'+replic);
        if(replic.size()>0)
        {
        List<case> casecount=[SELECT Origin, Subject, status, ContactId FROM case WHERE contactid in:replic];
        system.debug('casecount'+casecount.size());
        //logic for inserting new case, update contact count
        for(contact replica3:replic)
       {
           if(casecount.size()>0 || casecount.size()!=null)
           {
       replica3.Count_of_Cases__c=casecount.size()-noOfRecInCase1;
           system.debug('logic for inserting new case, update contact count'+replica3);
           }
        else{
            replica3.Count_of_Cases__c=noOfRecInCase1;
             system.debug('logic for inserting new case, update contact count1'+replica3);
        }
       }
        }
        update replic;
    }
}*/
error was like
Illegal assignment from List<AggregateResult> to List<Integer>
@istest
public class Accountupdatetest {
    @testsetup
    static void Fieldvalues()
    {
        Account accountList=new Account(name='bargavi',BillingPostalCode='56789');
         insert accountList ;
        Address__c adds=new Address__c(zip_code__c='56789',State_City__c='karntaka',Country__c='india',Street__c='dangal');
         insert adds;
    }
    @istest
   static void test1()
    {
         Account acc2=[select name,BillingPostalCode,BillingCity,BillingCountry,BillingStreet from Account ];
       // Address__C adds1=[select Street__c,Zip_code__c,State_City__c,Country__c from Address__C];

         test.startTest(); 
          acc2.BillingPostalCode='56789';
        try{
         update acc2; 
        }
        catch(DmlException exp)
        {
            system.assert(exp.getMessage().contains('no address zipcode matched to the billing postal code'));
        }
    
       test.stopTest(); 
    }
}
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
public class Accountupdate {
public static void Mymethod(List<Account> acc)
          {
//List<Account> addition=new List<Account>();
           set<String> Collectstring=new set<String>();
                 for(Account collectzipcode:acc)
                     {
                           Collectstring.add(collectzipcode.BillingPostalCode);
                           system.debug(' collect All the Zip code ids'+Collectstring);
                      }
            List<Address__c> fetch=[select Street__c,Zip_code__c,State_City__c,Country__c  from Address__c where Zip_code__c in:Collectstring];
             system.debug(+fetch);
            Map<String,Address__c> maping=new Map<String,Address__c>();
                for(Address__c edit:fetch)
                    {
                       maping.put(edit.Zip_code__c,edit);
                        system.debug('maping'+maping);
                     }
                      for(Account acc1:acc)
                             {
                                 List<Address__c> lstAdd=new List<Address__c>();
                               Address__c lastoutput=maping.get(acc1.BillingPostalCode);
                                 lstadd.add(lastoutput);
                                 system.debug('lastoutput'+lastoutput);
                                        if(lstadd.size()<>null)
                                          {
                                              acc1.BillingCity=lastoutput.State_City__c;
                                               acc1.BillingCountry=lastoutput.Country__c;
                                               acc1.BillingStreet=lastoutput.Street__c;
                                           }
                           else
                           {
                                     acc1.adderror('no address zipcode matched to the billing postal code');
                           }

                              }
            }
}
///////////////////////////////////////////////////////////////////////////////////////////////////////
error
//////////////////////
System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, addressontrigger: execution of BeforeInsert

caused by: System.NullPointerException: Attempt to de-reference a null object

Class.Accountupdate.Mymethod: line 27, column 1
Trigger.addressontrigger: line 3, column 1: []