• Antoninus Augustus
  • NEWBIE
  • 115 Points
  • Member since 2022

  • Chatter
    Feed
  • 4
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 13
    Replies

Hi,

I'm having difficulty in writing a test class for my apex class that creates a new lead record based on whether an existing lead has met the conditions.  So if a lead has Web to Lead = True and H M!=null and WTL G!=null, it will take the values from that record and create a new one.  Please see below class:

APEX CLASS:

public class CreateNewLead {
 
   public static void createnewrecords(List<Lead> leadMap){
 
        List<Lead> insertList = new List<Lead>();

        for (Lead rec:LeadMap){
               if ((rec.WTL_G__c != null) && (rec.H_M__c != null) && (rec.Web_to_Lead__c==TRUE))
               {                                          
                      // Creating new record
                       Lead newlist = new Lead();      
                       newlist.WTL_M__c = rec.H_M__c;                  
                       newlist.FirstName = rec.FirstName;
                       newlist.LastName = rec.LastName;
                       insertList.add(newlist);        
               }
             
         }
        
        if(insertList.size()>0){
        insert  insertList;  
        Constantclass.isenteredtrigger=true;
        }
   }
}

 

TEST CLASS:

@isTest
private class CreateNewLead_Test {
    
    
        static  testMethod void UPDATEMPRNGRPN_Test_TestMethod1(){
                       List<Lead> leadMap = new List<Lead>();
                       List<Lead> insertList = new List<Lead>();
                       Lead Ld = new Lead(FirstName='Name2', Web_To_Lead__c=TRUE, H_M__c='12345678901', WTL_G__c='1234567');
                       insert Ld;
                       insertList.add(Ld);
                       CreateNewLead.createnewrecords(insertList);
                       }     
               }

I'm getting 0% coverage on this class however I'm not sure on what I'm doing wrong.  Can someone please help?

Hi Folks,

I have a apex class which i am trying to execute via Developer console Anonymous apex
ERTT_TaskCreationValidation.isAccountResearchcompleted('01236000000OnsMAAS','01236000000OnsKAAS');

but getting the error as
Line: 1, Column: 28
Method does not exist or incorrect signature: void isAccountResearchcompleted(String, String) from the type ERTT_TaskCreationValidation


Here is Apex class for reference
 
public class ERTT_TaskCreationValidation {
    public static void isAccountResearchcompleted(List<Task> ERTTTasks,Set<Id> caseIdset)
    {
        map<id, Task> mapTaskDetails ;
		map<Id, Case> mapCaseWithTaskList = new  map<Id, Case>([select id, (Select id, Action__c from Tasks )  from Case where Id in: caseIdset]); 
        for(Task t : ERTTasks)
        {
            Boolean validationFlag = true;
            for(Task t1:  mapCaseWithTaskList.get(t.WhatId).tasks)
            {
                if(t1.Action__c == 'Airtel Account Research')
                {
                    validationFlag = false;
                }
            }
            if(validationFlag)
            {
                t.addError('Please Create a task for Airtel Account Research before creating any other Task');
            }
            
        }
    }
}

Your response in appreciated

Regards
Fiona
 
Hi Folks,

Apex class shows only 48% whereas wrote tests for all lines,any idea why shows only 48%

apex code
 
public class ETRR_TaskCreationValidation {
    public static void isairtel account contactResearchcompleted(List<Task> ETRRTasks,Set<Id> caseIdset)
    {
        map<id, Task> mapTaskDetails ;
        map<Id, Case> mapCaseWithTaskList = new  map<Id, Case>([select id, (Select id, Action__c from Tasks )  from Case where Id in: caseIdset]); 
        for(Task t : ETRRTasks)
        {
            Boolean validationFlag = true;
            
            for(Task t1:  mapCaseWithTaskList.get(t.WhatId).tasks)
            {
                if(t1.Action__c == 'airtel account contact Research')
                {
                    validationFlag = false;
                }
            }
            
            if(validationFlag)
            {
                t.addError('Please Create a task for airtel account contact Research before creating any other Task');
            }
            
        }
    }
    public static void is1stairtel contactcompleted(List<Task> ETRRTasks,Set<Id> caseIdset)
    {
        map<id, Task> mapTaskDetails ;
        map<Id, Case> mapCaseWithTaskList = new  map<Id, Case>([select id, (Select id, Action__c from Tasks )  from Case where Id in: caseIdset]); 
        for(Task t : ETRRTasks)
        {
            Boolean validationFlag = true;
            if(mapCaseWithTaskList.get(t.WhatId).tasks.size()>1){
                for(Task t1:  mapCaseWithTaskList.get(t.WhatId).tasks)
                {
                    
                    if( t1.Action__c == '1st airtel contact')
                    {
                        validationFlag = false;
                    }
                    
                }
                
            }
            if(validationFlag)
            {
                t.addError('Please Create a task for 1st airtel contact before creating any other Task');
            }
            
        }
    }
}

Here is test class
 
@isTest
public class ETRR_TaskCreationValidation_Test {
    
    @isTest
    private static void testETRRValidation()
    {
        Id caseRecordTypeId = [select id from Recordtype where DeveloperName  = 'Executive_Response' and sobjecttype = 'Case' ].Id ;
        Id taskrecordTypeId_ETRR = [select id, DeveloperName from RecordType where sobjecttype = 'Task' AND developername = 'ETRR_Task_Record_Type' ].Id; 
        
        Case c = new case(recordtypeId = caseRecordTypeId);
        insETRR c;
        
        try
        {
            task t = new task(recordtypeId = taskrecordTypeId_ETRR, WhatId = c.Id );
            insert t;
            task t2 = new task(recordtypeId = taskrecordTypeId_ETRR, WhatId = c.Id );
            insert t2;
        }
        Catch(System.DmlException dmlex)
        {
            system.assETRREquals('FIELD_CUSTOM_VALIDATION_EXCEPTION', dmlex.getDmlStatusCode(0));     
            task t = new task(recordtypeId = taskrecordTypeId_ETRR, WhatId = c.Id, Action__c = 'airtel account airtel contact Research' );
            insert t; 
            task t1 = new task(recordtypeId = taskrecordTypeId_ETRR, WhatId = c.Id );
            insert t1; 
             task t2 = new task(recordtypeId = taskrecordTypeId_ETRR, WhatId = c.Id, Action__c = '1st airtel contact' );
            insert t2; 
            task t3 = new task(recordtypeId = taskrecordTypeId_ETRR, WhatId = c.Id );
            insert t3; 
            
        }
        
        
    }
}

Your response is appreciated

Regards
Fiona
Hello there, I'm new in this domain, I'm trying to do before delete trigger execution with this code -
trigger Account_Trigger_after on Account (before delete)

    for(account a.Name = 'Bosch Limited'){
        a.Phone = '123456';
    }
}
I'm trying to change phone number to '123456' before deleting the account record.
I'm not sure if syntax needs some correction. kindly help..
 
Hi please help me write a test class for a schedulable apex class that sends an email to all users who have a checkbox on their user checked.
 
//Send email to users where receive Grants email = TRUE
public class NoActivityThisQrtr implements Schedulable {
    public void execute(SchedulableContext sc) {
        // Get list of opportunities where the opps> account last activity date not in the current quarter
        List<Opportunity> listOfnoactivityOps = [Select Id, Name, StageName ,Account_Name__c,Accouint_Last_Activity_Date__c
                                             From Opportunity 
                                             Where Accouint_Last_Activity_Date__c != THIS_FISCAL_QUARTER];
        
        // Get user ids in a list
        User adminProfile = [Select Id From User Where Receive_TB_Grant_Emails_Notifications__c = TRUE];
        List<Id> listOfUserIds = new List<Id>();
        for(User usr : [Select Id From User Where ProfileId = :adminProfile.Id]) {
            listOfUserIds.add(usr.Id);
        }
        
        // Get all the opportunities Name, StageName, Acccount and Account Last Activity Date in a String
        String closedOpportunities = 'Opportunity Name' + ' : ' + 'Stage' + ':' +'Account' + ':' +'Account Last Activity Date';
        for(Opportunity op : listOfnoactivityOps) {
            closedOpportunities = ClosedOpportunities + '\n' + op.Name + ' : ' + op.StageName + ':' + op.Account_Name__c +':' + OP.Accouint_Last_Activity_Date__c;
        }
        
        sendmail(listOfUserIds, closedOpportunities);
    }
    
    public void sendmail(List<Id> listOfUserIds, String closedOpportunities) {
        // Creating instance of email and set values
        Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
        email.setToAddresses(listOfUserIds);
        email.setSubject('Accounts without Activity this month');
        email.setPlainTextBody( 'Hello, Here are opportunities whose accounts havent had activity this quarter'+ 
            closedOpportunities);
        
        // Send email
        Messaging.sendEmail(new List<Messaging.SingleEmailMessage> {email});
    }
}

this is the test class i have, no errors but also no coverage
 
@isTest
private class NoActivityThisQrtrTest
{
    static testmethod void schedulerTest() 
    {
        String CRON_EXP = '0 0 0 15 3 ? *';
        
        // Create your test data
        List<Opportunity> listOfnoactivityOps = [Select Id, Name, StageName ,Account_Name__c,Accouint_Last_Activity_Date__c
                                             From Opportunity 
                                             Where Accouint_Last_Activity_Date__c != THIS_FISCAL_QUARTER];
        
        User adminProfile = [Select Id From User Where Receive_TB_Grant_Emails_Notifications__c = TRUE];
        List<Id> listOfUserIds = new List<Id>();
        for(User usr : [Select Id From User Where ProfileId = :adminProfile.Id]) {
            listOfUserIds.add(usr.Id);
        }
        
        Test.startTest();

            String jobId = System.schedule('ScheduleApexClassTest',  CRON_EXP, new NoActivityThisQrtr());
            CronTrigger ct = [SELECT Id, CronExpression, TimesTriggered, NextFireTime FROM CronTrigger WHERE id = :jobId];
            System.assertEquals(CRON_EXP, ct.CronExpression);
            System.assertEquals(0, ct.TimesTriggered);

        Test.stopTest();
    }
}

I have tried this test class and only got 17%
 
@istest
public with sharing class NoActivityThisQrtrTest {
    static testmethod void testSample() {
        Test.startTest();
        NoActivityThisQrtr obj = new NoActivityThisQrtr();
        obj.execute( null );
        Test.stopTest();
    }
}

 
  • June 24, 2022
  • Like
  • 0
I am trying to deploy a trigger in production and despite having 57% code coverage in Sandbox, I get the following error
Code Coverage Failure Your code coverage is 0%. You need at least 75% coverage to complete this deployment. Business_Hours
What am I missing:

My trigger is:

trigger Business_Hours on Lead (before insert) {
    //Selecting default business hours (BH) record
    BusinessHours defaultBH = [SELECT Id FROM BusinessHours WHERE IsDefault = true Limit 1];
    //Making sure BH record exists
    if(defaultBH != NULL){
        for(Lead leadObj : trigger.new ){
            //Making sure that first call made field is populated and is updated
            if(leadObj.Call_Made__c != NULL && Trigger.oldMap.get(leadObj.Id).Call_Made__c != leadObj.Call_Made__c){
               decimal result = BusinessHours.diff(defaultBH.Id, leadObj.CreatedDate, leadObj.Call_Made__c );
            Decimal resultingMinutes = result/(60000);
                //Populating result into custom field & setting number of decimals
                leadObj.Elapsed_Time__c = resultingMinutes.setScale(4); 
            }  
        }    
    } 
}
Test Class:
@isTest

public class Business_Hours_Test
{
    static testMethod void testUnit()
    {
        
        
        Lead led = new Lead();
        led.lastname = 'Test';
        led.firstName ='Test';
        led.company = 'ABC';
        led.Brand__c = 'Rain';
        led.Call_Made__c = System.today();
        led.CreatedDate = System.today();
        led.Elapsed_Time__c = 736;
        // Add all required field
        update led;
        
    }
}

Hi,

I'm having difficulty in writing a test class for my apex class that creates a new lead record based on whether an existing lead has met the conditions.  So if a lead has Web to Lead = True and H M!=null and WTL G!=null, it will take the values from that record and create a new one.  Please see below class:

APEX CLASS:

public class CreateNewLead {
 
   public static void createnewrecords(List<Lead> leadMap){
 
        List<Lead> insertList = new List<Lead>();

        for (Lead rec:LeadMap){
               if ((rec.WTL_G__c != null) && (rec.H_M__c != null) && (rec.Web_to_Lead__c==TRUE))
               {                                          
                      // Creating new record
                       Lead newlist = new Lead();      
                       newlist.WTL_M__c = rec.H_M__c;                  
                       newlist.FirstName = rec.FirstName;
                       newlist.LastName = rec.LastName;
                       insertList.add(newlist);        
               }
             
         }
        
        if(insertList.size()>0){
        insert  insertList;  
        Constantclass.isenteredtrigger=true;
        }
   }
}

 

TEST CLASS:

@isTest
private class CreateNewLead_Test {
    
    
        static  testMethod void UPDATEMPRNGRPN_Test_TestMethod1(){
                       List<Lead> leadMap = new List<Lead>();
                       List<Lead> insertList = new List<Lead>();
                       Lead Ld = new Lead(FirstName='Name2', Web_To_Lead__c=TRUE, H_M__c='12345678901', WTL_G__c='1234567');
                       insert Ld;
                       insertList.add(Ld);
                       CreateNewLead.createnewrecords(insertList);
                       }     
               }

I'm getting 0% coverage on this class however I'm not sure on what I'm doing wrong.  Can someone please help?

Anytime a new Customer account is created, and the Account Name is filled, the Customer

The name should be filled with the same name as the account Name, appended with “- Customer”

  • E.g.: Customer Account
  • Account Name: Recruitment
  • Customer Name: Recruitment – Customer
 

Similarly, every time a new partner account is created, the partner name should be Account

Name appended with “- Partner”

o Eg: Partner Account

o Account Name: Salesforce

o Partner Name Salesforce – Partner

Using triggers in apex I should am trying to do that but I don't know how to write the logic I have in mind which is to get the record type and then check if it is a Customer_Account or Partner_Account depending on that either append '-Customer' or '-Partner' as text in the respective name field   

trigger AccountTrigger on Account (before insert) {
    if(trigger.isInsert && trigger.isBefore){
        AccountTriggerHandler.AppendAccountName(trigger.new);
    }
}
this is the trigger 
and this is the handler class I am stuck on 
public class AccountTriggerHandler {
    public static void AppendAccountName(List<Account> newAccountList){

---------------------------------
I am thinking of smth like this but don't know how to code it write I am very new to apex 
 if{ recordtypeid.name==customer account
 then account a =[SELECT Customer_Name FROM account LIMIT 1];
a.Customer_Name = a.Name +'-Customer';
update a;
a.Partner_Name = a.Name +'-Customer';
update a;
 Account.Customer_name= Account.name +'-Customer'
 else Account.Partner_name= account.name +'-Partner'
 }
Hi Folks,

I have a apex class which i am trying to execute via Developer console Anonymous apex
ERTT_TaskCreationValidation.isAccountResearchcompleted('01236000000OnsMAAS','01236000000OnsKAAS');

but getting the error as
Line: 1, Column: 28
Method does not exist or incorrect signature: void isAccountResearchcompleted(String, String) from the type ERTT_TaskCreationValidation


Here is Apex class for reference
 
public class ERTT_TaskCreationValidation {
    public static void isAccountResearchcompleted(List<Task> ERTTTasks,Set<Id> caseIdset)
    {
        map<id, Task> mapTaskDetails ;
		map<Id, Case> mapCaseWithTaskList = new  map<Id, Case>([select id, (Select id, Action__c from Tasks )  from Case where Id in: caseIdset]); 
        for(Task t : ERTTasks)
        {
            Boolean validationFlag = true;
            for(Task t1:  mapCaseWithTaskList.get(t.WhatId).tasks)
            {
                if(t1.Action__c == 'Airtel Account Research')
                {
                    validationFlag = false;
                }
            }
            if(validationFlag)
            {
                t.addError('Please Create a task for Airtel Account Research before creating any other Task');
            }
            
        }
    }
}

Your response in appreciated

Regards
Fiona
 
Hello.

I have a business use case where we are looking to generate a unique identifier every time an Account record is created. The identifier needs to follow a specific format, so an autonumber field is not an option in this scenario.

We have a fairly simple bulkified trigger in place to generate this code. Basically, the trigger:
  • Queries all of the existing Account records for their existing unique identifiers (outside of the trigger loop) for comparison
  • Then, for each record in Trigger.new:
    • Generates a new code in the format we need
    • Compares it against all of the existing codes (from the Account query outside the loop)
      • If it's unique:
        • update the Account in Trigger.new
        • Add the code to the full Account query list so it’s included in the next comparison
      • If it's not unique, re-generate the code and repeat the process
This has worked well, but we've exceeded 50k Account records in our org, and the initial query to obtain all of the codes to check against is now failing. Since our unique code does contain the first letter of the Account name, I considered adding a WHERE clause to the Account query… but since that query has to be outside of the Trigger.new loop, I don’t believe that will work either. And, since the 50k limit is per transaction and not per query, splitting the Account query into multiple queries likely will not work either.

Any suggestions for an approach to this issue? Much appreciated. Thank you.

-Greg
 
Hi Folks,

Apex class shows only 48% whereas wrote tests for all lines,any idea why shows only 48%

apex code
 
public class ETRR_TaskCreationValidation {
    public static void isairtel account contactResearchcompleted(List<Task> ETRRTasks,Set<Id> caseIdset)
    {
        map<id, Task> mapTaskDetails ;
        map<Id, Case> mapCaseWithTaskList = new  map<Id, Case>([select id, (Select id, Action__c from Tasks )  from Case where Id in: caseIdset]); 
        for(Task t : ETRRTasks)
        {
            Boolean validationFlag = true;
            
            for(Task t1:  mapCaseWithTaskList.get(t.WhatId).tasks)
            {
                if(t1.Action__c == 'airtel account contact Research')
                {
                    validationFlag = false;
                }
            }
            
            if(validationFlag)
            {
                t.addError('Please Create a task for airtel account contact Research before creating any other Task');
            }
            
        }
    }
    public static void is1stairtel contactcompleted(List<Task> ETRRTasks,Set<Id> caseIdset)
    {
        map<id, Task> mapTaskDetails ;
        map<Id, Case> mapCaseWithTaskList = new  map<Id, Case>([select id, (Select id, Action__c from Tasks )  from Case where Id in: caseIdset]); 
        for(Task t : ETRRTasks)
        {
            Boolean validationFlag = true;
            if(mapCaseWithTaskList.get(t.WhatId).tasks.size()>1){
                for(Task t1:  mapCaseWithTaskList.get(t.WhatId).tasks)
                {
                    
                    if( t1.Action__c == '1st airtel contact')
                    {
                        validationFlag = false;
                    }
                    
                }
                
            }
            if(validationFlag)
            {
                t.addError('Please Create a task for 1st airtel contact before creating any other Task');
            }
            
        }
    }
}

Here is test class
 
@isTest
public class ETRR_TaskCreationValidation_Test {
    
    @isTest
    private static void testETRRValidation()
    {
        Id caseRecordTypeId = [select id from Recordtype where DeveloperName  = 'Executive_Response' and sobjecttype = 'Case' ].Id ;
        Id taskrecordTypeId_ETRR = [select id, DeveloperName from RecordType where sobjecttype = 'Task' AND developername = 'ETRR_Task_Record_Type' ].Id; 
        
        Case c = new case(recordtypeId = caseRecordTypeId);
        insETRR c;
        
        try
        {
            task t = new task(recordtypeId = taskrecordTypeId_ETRR, WhatId = c.Id );
            insert t;
            task t2 = new task(recordtypeId = taskrecordTypeId_ETRR, WhatId = c.Id );
            insert t2;
        }
        Catch(System.DmlException dmlex)
        {
            system.assETRREquals('FIELD_CUSTOM_VALIDATION_EXCEPTION', dmlex.getDmlStatusCode(0));     
            task t = new task(recordtypeId = taskrecordTypeId_ETRR, WhatId = c.Id, Action__c = 'airtel account airtel contact Research' );
            insert t; 
            task t1 = new task(recordtypeId = taskrecordTypeId_ETRR, WhatId = c.Id );
            insert t1; 
             task t2 = new task(recordtypeId = taskrecordTypeId_ETRR, WhatId = c.Id, Action__c = '1st airtel contact' );
            insert t2; 
            task t3 = new task(recordtypeId = taskrecordTypeId_ETRR, WhatId = c.Id );
            insert t3; 
            
        }
        
        
    }
}

Your response is appreciated

Regards
Fiona
When I execute this query
List<AggregateResult> query = [
    SELECT Max(Id) Id, AccountId, Max(CustomField__c) 
    FROM Asset WHERE Status = 'X' 
    AND (CustomField__c = 'Z' 
    OR CustomField__c = 'Y') 
    GROUP BY AccountId LIMIT 1000 
];

The first time, happen an error:
Internal Salesforce.com Error

But the second time, I executed this query, the result with success 

User-added image

Why does this happen?
Hello there, I'm new in this domain, I'm trying to do before delete trigger execution with this code -
trigger Account_Trigger_after on Account (before delete)

    for(account a.Name = 'Bosch Limited'){
        a.Phone = '123456';
    }
}
I'm trying to change phone number to '123456' before deleting the account record.
I'm not sure if syntax needs some correction. kindly help..
 
Hi Guys! 

I am newbie in Apex, but I am trying to write some code. The purpose was simple: I have PricebookEntry object on Salesforce, and 2 lookup fields: 
- Pricebook2Id
- Price_Book_2__c
I want to fill Price_Book_2__c with the same value as Pricebook2Id on each record.

When I opened and run batch in Anonymouse Window I get error: 
Line: 3, Column: 25
Variable does not exist: Pricebook2Id

Here is the Apex class: 

global class UpdatePriceBookCustomField implements Database.batchable<sObject>{
    global final String query;
    global Database.QueryLocator start (Database.BatchableContext BC) {
        return Database.getQueryLocator(query);}
    
    global void execute(Database.BatchableContext BC,List<sObject> scope){
        List<PricebookEntry>pbeToUpdate = new List<PricebookEntry>();
        
    for (sObject s : scope){PricebookEntry a = (PricebookEntry)s;
                            if(a.Price_Book_2__c==null){
                                a.Price_Book_2__c=a.Pricebook2Id;
                                pbeToUpdate.add(a);
                            }
                            }
    update pbeToUpdate;
        
    }
    global void finish(Database.BatchableContext BC) {
    }
}


Here is the batch: 
UpdatePriceBookCustomField PBE = new UpdatePriceBookCustomField();
PBE.query='Select Id, Pricebook2Id, Price_Book_2__c from PricebookEntry';
PBE.Price_Book_2__c=PBE.Pricebook2Id;
ID batchprocessid = Database.executeBatch(PBE);

Anyone has any idea why it don't want to run? I don't know why Apex is not seeing the Pricebook2Id...
Hi Guys,
I have a requirement to pass string "year" value dynamically to batch apex class from custom metadatatype. How can I achieve this to pass string value from custom metadatatype to batchclass and filter the records based on year value in SOQL query
I couldnt see debug statements aswell. its not showing error got 100% coverage. when i use database.execute batch totalbatch processed it shows 1 and zero failures. only after schedule it shows  total batch zero in apex jobs.can anyone guide me to resolve this issue?

global class UpdateAccountRating implements Database.Batchable<sObject> {
   
 global  Database.QueryLocator start(Database.BatchableContext bc) {
     set<string> strlist = new set<string>{'workInprogress','Delivered','ClosedWon'};
      string query='select id, stageName,AccountId, Account.Rating from opportunity where stageName IN :strlist AND AccountId !=Null';
     system.debug('query=='+query);
     return Database.getQueryLocator(query); 
    }
     global Void execute(Database.BatchableContext bc, List<opportunity> Scope){
      
        for(opportunity o :Scope){
            o.Account.Rating='client';  
          system.debug('Rating'+o.Account.Rating);
           
        }
         update Scope;}
         global void finish(Database.BatchableContext bc){
       
        AsyncApexJob job = [SELECT Id, Status,NumberOfErrors,JobItemsProcessed,TotalJobItems, CreatedBy.Email 
                            FROM AsyncApexJob
                            WHERE Id = :bc.getJobId()];  
    }   
     } 

testclass
@isTest
public class UpdateAccountRatingTest {
    @isTest
    public static void unit_test(){
      
        Account acc =new Account();
        acc.Name = 'test';
        acc.Rating='prospect';
        insert acc;
        
        
        Opportunity opp = new opportunity();
        opp.Name = 'test opp';
        opp.Accountid = acc.Id;
        opp.stageName = 'workInprogress';
        opp.CloseDate = system.today()+5;
        insert opp;
         
       
        
        Test.startTest();
      
        UpdateAccountRating uar  = new UpdateAccountRating();
        Database.executeBatch(uar);
      String sch = '0 0 0 1 * ? *';
      string JobID = system.schedule('BatchJob',sch, new UpdateAccountRatingSchedular());
        Test.stopTest();
       

 }
    }
schedular
global class UpdateAccountRatingSchedular implements Schedulable {
global void execute(SchedulableContext sc){
        UpdateAccountRating uar = new UpdateAccountRating();
        database.executebatch(uar);
    }
}


Thanks in advance