You need to sign in to do that
Don't have an account?
RJ12
Test Class for Batch Apex that invokes a Flow
I wrote a batch apex that invokes a Flow interview. Somehow my Test class is not covering execute method. Can anyone help me out?
Batch Apex:
Test Class:
Reminder_date__c, Rev_Date__c are 'Date' fields. These fields will be populated by a workflow when Lead status is 'Qualify'.
Batch Apex:
global class Lead_remind implements Database.Batchable<sObject>{ global Database.QueryLocator start(Database.BatchableContext BC) { Date d = Date.today(); String query = 'SELECT Id, OwnerId, Reminder_date__c, Rev_Date__c, Status FROM Lead where Status=\'Qualify\' AND Reminder_date__c=:d'; return Database.getQueryLocator(query); } global void execute(Database.BatchableContext BC, List<Lead> scope) { for(Lead l : scope) { Map<String, Object> params = new Map<String, Object>(); params.put('LId',l.Id); params.put('LeadOwnerId',l.OwnerId); params.put('BusinessDay_3',l.Reminder_date__c); params.put('BusinessDay_4',l.Rev_Date__c); Flow.Interview.Lead_Flow lFlow = new Flow.Interview.Lead_Flow(params); lFlow.start(); } update scope; } global void finish(Database.BatchableContext BC) { } }
Test Class:
@isTest private class Lead_remind_Test { static testMethod void testMethod1() { Lead L= new Lead(); L.OwnerId = '0055A00000A6s5pLAQ'; L.LastName ='Lead Name'; L.Company = 'Lead Company'; L.Status = 'New'; L.LeadSource = 'Social'; L.Phone = '7364859473'; insert L; L.Reminder_date__c = Date.today(); L.Status = 'Qualify'; update L; Test.startTest(); Lead_remind obj = new Lead_remind(); DataBase.executeBatch(obj); Test.stopTest(); } }
Reminder_date__c, Rev_Date__c are 'Date' fields. These fields will be populated by a workflow when Lead status is 'Qualify'.
Your code is appearing right. Can you debug to see if the scope in execute method has some values in it?
Thanks.
You need to change your SOQL query in main class as below
this is the complete code
@Raj Vakati,
My requirement is, Reminder_date__c will be populated with some date by a workflow field update. I have to invoke the visual flow whenever the lead status is 'Qualify' and Reminder_date__c = today.
Is this query will give the correct result?
@pranav_sanvatsarkar
The code is working fine. The class executes and also invokes the flow.
If you keep it in to single quote all will be string and no date value will be populated
@Raj Vakati,
I'm not populating any date values in the code. I'm checking whether the Lead status is 'Qualify' and Reminder_date__c = today's date or not.
If Reminder date is today's date and Status is Qualify then it should invoke the flow.
@Raj Vakati,
Can you help me understand, with this query are we populating todays' date value to Reminder_date__c?