You need to sign in to do that
Don't have an account?
Ishan Singh 4
Can anyone suggest what is wrong in my test class
batchClass
global class BirthdayCard implements Database.Batchable<sObject> {
global Database.QueryLocator start(Database.BatchableContext bc)
{
return Database.getQueryLocator([SELECT dateOfBirth__c,Id,Possible_Followup_Date__c FROM Lead WHERE dateOfBirth__c = NEXT_N_DAYS:7 AND Possible_Followup_Date__c != null]);
}
global void execute(Database.BatchableContext bc, List<Task> scope)
{
for(Task l : scope)
{
Task B = new Task();
B.Subject= 'Send Birthday Card';
B.ActivityDate = date.today();
B.OwnerId = l.OwnerId;
B.WhoId=l.Id;
}
insert scope;
}
global void finish(Database.BatchableContext bc){}
}
testClass:
@isTest
public class BirthdayCardTest{
@isTest
public static void BirthdayCard(){
List<Lead> leadList = new List<Lead>();
{
Lead ld = new Lead();
ld.lastname = 'test';
ld.dateOfBirth__c = date.today().addDays(7);
ld.Status = 'Unqualified';
ld.State__c='Test';
ld.Policy_DB_Amount__c=100000;
ld.Company='Mirketa';
ld.Possible_Followup_Date__c=date.today()
leadList.add(ld);
}
insert leadList;
Test.startTest();
Database.executeBatch(new BirthdayCard());
Test.stopTest();
}
}
global class BirthdayCard implements Database.Batchable<sObject> {
global Database.QueryLocator start(Database.BatchableContext bc)
{
return Database.getQueryLocator([SELECT dateOfBirth__c,Id,Possible_Followup_Date__c FROM Lead WHERE dateOfBirth__c = NEXT_N_DAYS:7 AND Possible_Followup_Date__c != null]);
}
global void execute(Database.BatchableContext bc, List<Task> scope)
{
for(Task l : scope)
{
Task B = new Task();
B.Subject= 'Send Birthday Card';
B.ActivityDate = date.today();
B.OwnerId = l.OwnerId;
B.WhoId=l.Id;
}
insert scope;
}
global void finish(Database.BatchableContext bc){}
}
testClass:
@isTest
public class BirthdayCardTest{
@isTest
public static void BirthdayCard(){
List<Lead> leadList = new List<Lead>();
{
Lead ld = new Lead();
ld.lastname = 'test';
ld.dateOfBirth__c = date.today().addDays(7);
ld.Status = 'Unqualified';
ld.State__c='Test';
ld.Policy_DB_Amount__c=100000;
ld.Company='Mirketa';
ld.Possible_Followup_Date__c=date.today()
leadList.add(ld);
}
insert leadList;
Test.startTest();
Database.executeBatch(new BirthdayCard());
Test.stopTest();
}
}
Please tell us your requirement and is your batch class is giving propr output?
You are getting data from Lead object and you are referring Task object in execute parameter. Please check this.
Thank You,
Dhanik
You can use below approachs for this requirement
1. https://success.salesforce.com/answers?id=9063A000000pYCnQAM for your requirement.
2. https://help.salesforce.com/articleView?id=000328974&language=en_US&type=1&mode=1
Thank You,
Dhanik Sahni
SalesforceCodex.com