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
SrinivasSrinivas 

Test Methodd


public static void logError(Exception ex)
  {
   Contact  errorLog = new Contact ();

       errorLog.MailingAddress='Errorlog@gmail.com';
       errorLog.Name='Record Updation';
 
       Database.insert(errorLog , false);
  }

Can Any one help test method for this

Sai PraveenSai Praveen (Salesforce Developers) 
Hi Srinivas,

I have created a test class as below and it covered 100%. Just replace logErrorclass with your class in which the above method is present.
 
@istest
public class logErrorclassTest {
static testmethod void testM(){

       
    Test.startTest();
       try{
    Account a = [Select id, name from account limit 1];
    a.name = '';
    update a;    
}
Catch(Exception e){
    system.debug('Exception ' + e);
    
    logErrorclass.logError(e);
}
            
    Test.stopTest();
       
    }   
}

If this solution helps, please mark it as best answer.

Thanks,
 
McCuboMcCubo
@Srinivas,
Just remember that a good test class doesn't cover just code coverage, but also use case coverage. Always add assertions to make sure the method/process is behaving as expected.