You need to sign in to do that
Don't have an account?
Michael M
Help with test class for schedulable
Hello, I have the below apex class that is to be used to schedule merging duplicates. How would I write a test class for this? thank you!
global class purgeClDupsSchedulable implements Schedulable{
global void execute(SchedulableContext SC) {
//** Tweak your account selection ... aka where clause ..
List<AggregateResult> MyMergeList = [SELECT Count(ID) , first_name__c, last_name__c, referral_account__c
FROM Community_Lead__c
WHERE from_lost_referral__c=TRUE
GROUP BY first_name__c, last_name__c, referral_account__c
HAVING Count(ID) > 1
ORDER BY Count(ID) desc
LIMIT 2000];
For (AggregateResult Agm : MyMergeList){
String firstName = string.valueOf(agm.get('first_name__c'));
String lastName = string.valueOf(agm.get('last_name__c'));
date dob = date.valueOf(agm.get('dob__c'));
community_lead__c ToAccount = [Select id, first_name__c, last_name__c from community_lead__c
where first_name__c like :firstName and last_name__c like :lastName and dob__c = :dob and createddate= today limit 1];
community_lead__c FromAccount = [Select id, first_name__c, last_name__c from community_lead__c
where Id != :ToAccount.Id and first_name__c like :firstName and last_name__c like :lastName and dob__c = :dob and createddate= today Limit 1];
database.merge(ToAccount , FromAccount );
}
}
}
global class purgeClDupsSchedulable implements Schedulable{
global void execute(SchedulableContext SC) {
//** Tweak your account selection ... aka where clause ..
List<AggregateResult> MyMergeList = [SELECT Count(ID) , first_name__c, last_name__c, referral_account__c
FROM Community_Lead__c
WHERE from_lost_referral__c=TRUE
GROUP BY first_name__c, last_name__c, referral_account__c
HAVING Count(ID) > 1
ORDER BY Count(ID) desc
LIMIT 2000];
For (AggregateResult Agm : MyMergeList){
String firstName = string.valueOf(agm.get('first_name__c'));
String lastName = string.valueOf(agm.get('last_name__c'));
date dob = date.valueOf(agm.get('dob__c'));
community_lead__c ToAccount = [Select id, first_name__c, last_name__c from community_lead__c
where first_name__c like :firstName and last_name__c like :lastName and dob__c = :dob and createddate= today limit 1];
community_lead__c FromAccount = [Select id, first_name__c, last_name__c from community_lead__c
where Id != :ToAccount.Id and first_name__c like :firstName and last_name__c like :lastName and dob__c = :dob and createddate= today Limit 1];
database.merge(ToAccount , FromAccount );
}
}
}
You can use the following code to get started. I used a sample cron expression but you can use cron maker to build cron expressions for your test class
If it helps, please mark this as solved
Anudeep
All Answers
You can use the following code to get started. I used a sample cron expression but you can use cron maker to build cron expressions for your test class
If it helps, please mark this as solved
Anudeep