function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
randheer practiserandheer practise 

how to write test class to the undelete class with 100 coverage including try catch blocks


public class UndeleteDml {
    public static void undeleteAccount()
    {
        List<Account> accounts=[SELECT id,Name FROM Account WHERE name like 'siri rao' all rows];
        system.debug('No of undeleted records are============'+accounts.size());
        try{
            undelete accounts;
            system.debug('No of records in Account============'+accounts);
            system.debug('records were undeleted from recyle bin successfully');
           }catch(Exception e){
                system.debug('sorry records were not undeleted');
               }
    }
}
thanks in advance
Best Answer chosen by randheer practise
BALAJI CHBALAJI CH
Hi Randheer,
You can just create a account with name like 'siri rao' and by invoking the above class static method in Test Class, the code will be covered.
Please find below Test Class for your above Class:
@isTest
public class UndeleteDml_test {
    public static testMethod void test1()
    {
        test.startTest();
        Account a = new Account();
        a.Name='siri rao';
        insert a;
        
        DeleteDml.undeleteAccount();
        Test.stopTest();
    }
}

Let us know if that helps you. Appreciate your response.

Best Regards,
BALAJI