Skip to content

Commit

Permalink
ALR-192
Browse files Browse the repository at this point in the history
  • Loading branch information
Kipa24 committed Jun 24, 2024
1 parent 38ca20a commit e2b7c3a
Show file tree
Hide file tree
Showing 5 changed files with 405 additions and 0 deletions.
170 changes: 170 additions & 0 deletions Archive/ALR/Flows/Task_Created_on_Account_Record.flow-meta.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
<?xml version="1.0" encoding="UTF-8"?>
<Flow xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>61.0</apiVersion>
<decisions>
<name>CheckTodayDate</name>
<label>Check Todays Date</label>
<locationX>182</locationX>
<locationY>252</locationY>
<defaultConnectorLabel>Default Outcome</defaultConnectorLabel>
<rules>
<name>checksforMarch15</name>
<conditionLogic>and</conditionLogic>
<conditions>
<leftValueReference>Checks</leftValueReference>
<operator>EqualTo</operator>
<rightValue>
<booleanValue>true</booleanValue>
</rightValue>
</conditions>
<connector>
<targetReference>GroupDetails</targetReference>
</connector>
<label>checks for March15</label>
</rules>
</decisions>
<environments>Default</environments>
<formulas>
<name>Checks</name>
<dataType>Boolean</dataType>
<expression>AND(
MONTH(TODAY()) = 6,
DAY(TODAY()) = 23
)</expression>
</formulas>
<formulas>
<name>DueDate</name>
<dataType>Date</dataType>
<expression>DATE(YEAR(TODAY()), 1, 10)</expression>
</formulas>
<interviewLabel>Task Created on Account Record {!$Flow.CurrentDateTime}</interviewLabel>
<label>Task Created on Account Record</label>
<processMetadataValues>
<name>BuilderType</name>
<value>
<stringValue>LightningFlowBuilder</stringValue>
</value>
</processMetadataValues>
<processMetadataValues>
<name>CanvasMode</name>
<value>
<stringValue>AUTO_LAYOUT_CANVAS</stringValue>
</value>
</processMetadataValues>
<processMetadataValues>
<name>OriginBuilderType</name>
<value>
<stringValue>LightningFlowBuilder</stringValue>
</value>
</processMetadataValues>
<processType>AutoLaunchedFlow</processType>
<recordCreates>
<name>NewTask</name>
<label>NewTask</label>
<locationX>50</locationX>
<locationY>468</locationY>
<inputAssignments>
<field>ActivityDate</field>
<value>
<elementReference>DueDate</elementReference>
</value>
</inputAssignments>
<inputAssignments>
<field>OwnerId</field>
<value>
<elementReference>GroupDetails.Id</elementReference>
</value>
</inputAssignments>
<inputAssignments>
<field>Priority</field>
<value>
<stringValue>Normal</stringValue>
</value>
</inputAssignments>
<inputAssignments>
<field>Status</field>
<value>
<stringValue>Not Started</stringValue>
</value>
</inputAssignments>
<inputAssignments>
<field>Subject</field>
<value>
<stringValue>Update Upcoming Renewals &amp; Reminder Email Template</stringValue>
</value>
</inputAssignments>
<inputAssignments>
<field>WhatId</field>
<value>
<elementReference>$Record.Id</elementReference>
</value>
</inputAssignments>
<object>Task</object>
<storeOutputAutomatically>true</storeOutputAutomatically>
</recordCreates>
<recordLookups>
<name>GroupDetails</name>
<label>GroupDetails</label>
<locationX>50</locationX>
<locationY>360</locationY>
<assignNullValuesIfNoRecordsFound>false</assignNullValuesIfNoRecordsFound>
<connector>
<targetReference>NewTask</targetReference>
</connector>
<filterLogic>and</filterLogic>
<filters>
<field>DeveloperName</field>
<operator>EqualTo</operator>
<value>
<stringValue>AdministrativeTasksQueue</stringValue>
</value>
</filters>
<filters>
<field>Type</field>
<operator>EqualTo</operator>
<value>
<stringValue>Queue</stringValue>
</value>
</filters>
<getFirstRecordOnly>true</getFirstRecordOnly>
<object>Group</object>
<storeOutputAutomatically>true</storeOutputAutomatically>
</recordLookups>
<start>
<locationX>56</locationX>
<locationY>0</locationY>
<connector>
<targetReference>CheckTodayDate</targetReference>
</connector>
<filterLogic>or</filterLogic>
<filters>
<field>Status__c</field>
<operator>EqualTo</operator>
<value>
<stringValue>Registered Active</stringValue>
</value>
</filters>
<filters>
<field>Status__c</field>
<operator>EqualTo</operator>
<value>
<stringValue>Registered Active with Conditions</stringValue>
</value>
</filters>
<filters>
<field>Status__c</field>
<operator>EqualTo</operator>
<value>
<stringValue>Registered Active Progressive Enforcement</stringValue>
</value>
</filters>
<object>Account</object>
<schedule>
<frequency>Daily</frequency>
<startDate>2024-03-01</startDate>
<startTime>00:00:00.000Z</startTime>
</schedule>
<triggerType>Scheduled</triggerType>
</start>
<status>Active</status>
</Flow>
109 changes: 109 additions & 0 deletions src/main/default/classes/ScheduleSendEmail.cls
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
/**
* @Name : ScheduledEmailTrigger
* @Description : Class for Sending Email on Jan-15
* @Author : Keerthana Srinivasan (Accenture)
* @StoryNo : ALR-562
**/

public with sharing class ScheduleSendEmail implements Schedulable {

public static Set<Id> accountIds = new Set<Id>();

public void execute(SchedulableContext sc) {
Date currentDate = Date.today();
if(currentDate.month() == 1 && currentDate.day() == 15){
try {
Map<Id, Set<Id>> accountIdToContactIdsMap = new Map<Id, Set<Id>>();

List<Account> accounts = [
SELECT Id
FROM Account
WHERE Status__c IN ('Registered Active', 'Registered Active with Conditions', 'Registered Active Progressive Enforcement')
];

for (Account acc : accounts) {
accountIds.add(acc.Id);
accountIdToContactIdsMap.put(acc.Id, new Set<Id>());
}

Map<Id, Account> accountIdToAccountMap = new Map<Id, Account>([
SELECT Id,
(SELECT Id, ContactId, Contact.Name, Contact.Email
FROM AccountContactRelations
WHERE IsActive = true AND Contact.Email != null)
FROM Account
WHERE Id IN :accountIds
]);

for (Account acc : accountIdToAccountMap.values()) {
for (AccountContactRelation acr : acc.AccountContactRelations) {
accountIdToContactIdsMap.get(acc.Id).add(acr.ContactId);
}
}

List<Id> contactIdsList = new List<Id>();
for (Set<Id> contactIds : accountIdToContactIdsMap.values()) {
contactIdsList.addAll(contactIds);
}

if (!contactIdsList.isEmpty()) {
sendRenewalDueEmail(contactIdsList);
}

} catch (Exception e) {
System.debug('Exception occurred in execute method: ' + e.getMessage());
}
}
}
public static void sendRenewalDueEmail(List<Id> contactIds) {
try {
EmailTemplate emailTemplate = getEmailTemplate('Upcoming_Renewal_Email_Template');

if (emailTemplate != null && emailTemplate.Id != null) {
OrgWideEmailAddress orgWideAddr = [
SELECT Id, DisplayName, Address
FROM OrgWideEmailAddress
WHERE DisplayName = 'ALR Support Email'
];

List<Messaging.SingleEmailMessage> emails = new List<Messaging.SingleEmailMessage>();

for (Id contactId : contactIds) {
Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
email.setTemplateId(emailTemplate.Id);
email.setOrgWideEmailAddressId(orgWideAddr.Id);
email.setTargetObjectId(contactId);
String emailSubject = emailTemplate.Subject;
String emailBody = emailTemplate.HtmlValue;

email.setSubject(emailSubject);
email.setHtmlBody(emailBody);
emails.add(email);
}

if (!emails.isEmpty()) {
Messaging.sendEmail(emails);
System.debug('Sent ' + emails.size() + ' email messages successfully.');
}
}
} catch (Exception e) {
System.debug('Exception occurred in sendRenewalDueEmail method: ' + e.getMessage());
}
}

// Method to retrieve email template by Developer Name
public static EmailTemplate getEmailTemplate(String templateDevName) {
EmailTemplate emailTemplateRec = null;
try {
emailTemplateRec = [
SELECT Id, DeveloperName, Subject, HtmlValue, Body
FROM EmailTemplate
WHERE DeveloperName = :templateDevName
LIMIT 1
];
} catch (Exception ex) {
System.debug('Exception occurred in getEmailTemplate method: ' + ex.getMessage());
}
return emailTemplateRec;
}
}
5 changes: 5 additions & 0 deletions src/main/default/classes/ScheduleSendEmail.cls-meta.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>57.0</apiVersion>
<status>Active</status>
</ApexClass>
Loading

0 comments on commit e2b7c3a

Please sign in to comment.