You need to sign in to do that
Don't have an account?
Clement Debrueres-Bartoli
Issue with Scheduled Apex class to Update Case
Hey Salesforce friends :),
I am having an issue with these 2 classes. In Sandbox I get 85% code coverage, but when I deploy it goes to 30%. There must be something wrong but I can't manage to find out the bug. Any idea on how I could improve it? Thank you very much.
And its Test class:
I am having an issue with these 2 classes. In Sandbox I get 85% code coverage, but when I deploy it goes to 30%. There must be something wrong but I can't manage to find out the bug. Any idea on how I could improve it? Thank you very much.
global class CaseUpdateReminder1 implements Database.Batchable<Sobject> ,System.Schedulable{ global Database.QueryLocator start(Database.BatchableContext bc) {return Database.getQueryLocator([SELECT Id FROM Case WHERE Eligible_Case__c='Yes' AND Reminder_1_Period__c = TRUE]); } global void execute(Database.BatchableContext bc, List<Case> scope) {for (Case Cases : scope) { Cases.Priority = 'High'; Cases.Internal_Action_Needed__c = 'Send Email'; Cases.Reminder_1_Field_Update_Done__c = TRUE; Cases.OwnerId = '00G3W000001LjOcUAK' } update scope; } global void finish(Database.BatchableContext bc){} global void execute(SchedulableContext SC){ Database.executeBatch(new CaseUpdateReminder1(), 50); } }in the code above, "Reminder_1_Period__c" is a formula field, TRUE if CreatedDate=TODAY, which is why I put the CreatedDate in the Test.
And its Test class:
@isTest public class CaseUpdateReminder1_Test { static testMethod void testMethod1() { List<Case> lstCase = new List<Case>(); Case cas = new Case(); cas.OwnerId = '0053W000001LxTEQA0'; cas.RecordTypeId = '0123W000000L3JSQA0'; cas.Priority = 'Medium'; case.CreatedDate = date.parse('10/02/2022'), cas.Reminder_1_Field_Update_Done__c = FALSE; cas.UID__c = 'Test12345'; lstCase.add(cas); insert lstCase; Test.startTest(); CaseUpdateReminder1 obj = new CaseUpdateReminder1(); DataBase.executeBatch(obj); Test.stopTest(); } }Thank you very much and all the best :)
In the test class I don't see the record has Reminder_1_Period__c as True because of which it is not returning any result to execute method i guess. Can you check it once.
If this solution helps, Please mark it as best answer.
Thanks,
Reminder_1_Period__c seems to be Boolean field type and also can you share the screenshot for which part the code is not covering.
Thanks,
you're right Reminder_1_Period__c is Bool but it's a formula:in Apex I get this error if I try to write it: Error: Compile Error: Field is not writeable: Case.Reminder_1_Period__c at line 17 column 11.
It seems the part that is not covered is only the 2 lines at the end, all the rest is blue: