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

Hi i need help with code coverage in this class!

I am a newbie and I find the code coverage very difficult, if anyone can help me, would be grateful, 


This is the class.



global class ScheduledProducts implements Schedulable {
global void execute(SchedulableContext SC){

Datetime fivedays =;

List<Products__c> lastDays=
[SELECT Is_Approved__c, CreatedDate FROM Products__c
WHERE CreatedDate <: fivedays AND Is_Approved__c = false];

for(Products__c a : lastDays){
if(a.Is_Approved__c == false) {
a.Is_Approved__c = true;


Thanks in advance!



Try the below code snippet as reference:



class ScheduleTestClassProduct {


   static testmethod void test()



   Products__c Pro = new Products__c(Name='testName',Is_Approved__c=false);


        insert Pro;


       String dateTime113 = '0 0 0 3 9 ? 2022';

      String jobId = System.schedule('testBasicScheduledApex',dateTime113 , new ScheduledProducts());


      CronTrigger ct = [SELECT Id, CronExpression, TimesTriggered , NextFireTime  FROM CronTrigger WHERE id = :jobId];





For more detail follow below link:


Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved. 


Hi, thanks for you reply.


Eclipse show a error : Field is not writeable: Products__c.Name 


Products__c Pro = new Products__c(Name='testName',Is_Approved__c=false);






I think the test should check the products that were created for five days or more, and these are approved after the scheduled run.