Skip to content

Commit

Permalink
Merge pull request #130 from Salesforce-org-Impact-Labs/feature/initi…
Browse files Browse the repository at this point in the history
…al-referral-task

create an initial referral when triggered to do so by a task
  • Loading branch information
dragongrrl authored Jul 9, 2020
2 parents 02b49a3 + 466db2c commit c72d713
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -1,23 +1,37 @@
global class Batch_SendInitialClientReferrals implements Database.Batchable<SObject>, Schedulable {
private static final String REMINDER_TASK_SUBJECT = 'Info to Client';
private static final String TASK_STATUS_COMPLETED = 'Completed';

global Database.QueryLocator start(Database.BatchableContext context) {
// select referrals for which we have sent no messages
return Database.getQueryLocator([
SELECT
Id
FROM Referral__c
WHERE Id NOT IN (SELECT Referral__c FROM Referral_Response__c)
Id,
WhatId,
Status
FROM Task
WHERE Subject = :REMINDER_TASK_SUBJECT
AND Status != :TASK_STATUS_COMPLETED
]);
}

global void execute(Database.BatchableContext context, List<Referral__c> referrals) {
if (!referrals.isEmpty()) {
List<Id> referralIds = new List<Id>();
for (Referral__c referral : referrals) {
referralIds.add(referral.Id);
global void execute(Database.BatchableContext context, List<Task> referralTasks) {
// get the referral ids from each task
List<Id> referralIds = new List<Id>();
for (Task referralTask : referralTasks) {
if (!referralIds.contains(referralTask.WhatId)) {
referralIds.add(referralTask.WhatId);
}
}
// send the emails
if (!referralIds.isEmpty()) {
EmailService.sendInitialReferralMessages(referralIds);
}
// update the tasks to completed
for (Task completedTask : referralTasks) {
completedTask.Status = TASK_STATUS_COMPLETED;
}
update referralTasks;
}

global void finish(Database.BatchableContext context) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ global class Batch_SendReferralFollowupReminders implements Database.Batchable<S
WhatId,
Status
FROM Task
WHERE ActivityDate = TODAY
AND Subject = :REMINDER_TASK_SUBJECT
WHERE Subject = :REMINDER_TASK_SUBJECT
AND Status != :TASK_STATUS_COMPLETED
]);
}
Expand All @@ -21,10 +20,14 @@ global class Batch_SendReferralFollowupReminders implements Database.Batchable<S
// get the referral ids from each task
List<Id> referralIds = new List<Id>();
for (Task reminderTask : reminderTasks) {
referralIds.add(reminderTask.WhatId);
if (!referralIds.contains(reminderTask.WhatId)) {
referralIds.add(reminderTask.WhatId);
}
}
if (!referralIds.isEmpty()) {
// send the messages
EmailService.sendReferralFollowupMessages(referralIds);
}
// send the messages
EmailService.sendReferralFollowupMessages(referralIds);
// update the tasks to completed
for (Task completedTask : reminderTasks) {
completedTask.Status = TASK_STATUS_COMPLETED;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ public class Test_BatchSendInitialClientReferrals {
);
insert ref1;

Task task1 = new Task(
Subject = 'Info to Client',
ActivityDate = System.today(),
WhatId = ref1.Id
);
insert task1;

Service__c svc2 = new Service__c (
Name = 'Test Another Service',
City__c = 'Dallas',
Expand All @@ -55,7 +62,15 @@ public class Test_BatchSendInitialClientReferrals {
Score__c = 2,
Service__c = svc2.Id
);
insert ref2;
insert ref2;

Task task2 = new Task(
Subject = 'Info to Client',
ActivityDate = System.today(),
WhatId = ref2.Id
);
insert task2;

}

static testMethod void testSendMessages() {
Expand Down

0 comments on commit c72d713

Please sign in to comment.