This guide outlines the process for updating the SMS notification system in Salesforce, including deactivating old flows, creating a new flow, and updating appointment records.
Step 1: Deactivate Old Flows
-
Deactivate the following flows:
-
Fire SMS Notifications If Appointment is Rescheduled
-
Confirmation SMS And Reschedule SMS
-
SMS Reminder 1
-
SMS Reminder 2
Step 2: Create a Copy of the New Flow
-
Locate the flow named "Send Appointiv SMS to Clients"
-
Create a copy of this flow
-
Name the copy "Local Copy Send Appointiv SMS to Clients" (This prevents the new flow from being changed when the app updates)
-
Activate the copied flow
Step 3: Modify the Active Flow
-
Open the active "Local Copy Send Appointiv SMS to Clients" flow
-
Navigate to the "Run Immediately" path
-
Edit the "Send Reschedule SMS now?" decision step
-
Change the condition:
-
From: "{!$Record.Appointed__StartDateTime__c}" "is changed" = True
-
To: "{!$Record.Appointed__StartDateTime__c}" "is changed" = False
-
-
Save and activate the flow
Step 4: Update Appointment Records
This step updates all future appointment records to trigger the new flow's time-based reminders.
4.1 Roll Time Forward
Run the following Apex code in the Developer Console:
// Get current datetime
DateTime now = DateTime.now();
// Query for Appointment Detail records where StartDateTime is in the future
// and Event Type is 'Appointment'
List<Appointed__Appointment_Detail__c> appointmentsToUpdate = [
SELECT Id, Appointed__StartDateTime__c, Appointed__EndDateTime__c
FROM Appointed__Appointment_Detail__c
WHERE Appointed__StartDateTime__c > :now
AND Appointed__Event_Type__c = 'Appointment'
];
// Iterate through the appointments and add 1 second to both start and end times
for (Appointed__Appointment_Detail__c appt : appointmentsToUpdate) {
appt.Appointed__StartDateTime__c = appt.Appointed__StartDateTime__c.addSeconds(1);
appt.Appointed__EndDateTime__c = appt.Appointed__EndDateTime__c.addSeconds(1);
}
// Update the records
if (!appointmentsToUpdate.isEmpty()) {
try {
update appointmentsToUpdate;
System.debug('Successfully updated ' + appointmentsToUpdate.size() + ' appointment records.');
} catch (DmlException e) {
System.debug('An error occurred while updating appointment records: ' + e.getMessage());
for (Integer i = 0; i < e.getNumDml(); i++) {
System.debug('Error on record ' + e.getDmlId(i) + ': ' + e.getDmlMessage(i));
}
}
} else {
System.debug('No appointment records found that meet the criteria for update.');
}
4.2 Roll Time Back
Next, roll back that change (note- this step is not strictly needed but cleans up the appointment start times just in case)
// Get current datetime
DateTime now = DateTime.now();
// Query for Appointment Detail records where StartDateTime is in the future
// and Event Type is 'Appointment'
List<Appointed__Appointment_Detail__c> appointmentsToUpdate = [
SELECT Id, Appointed__StartDateTime__c, Appointed__EndDateTime__c
FROM Appointed__Appointment_Detail__c
WHERE Appointed__StartDateTime__c > :now
AND Appointed__Event_Type__c = 'Appointment'
];
// Iterate through the appointments and subtract 1 second from both start and end times
for (Appointed__Appointment_Detail__c appt : appointmentsToUpdate) {
appt.Appointed__StartDateTime__c = appt.Appointed__StartDateTime__c.addSeconds(-1);
appt.Appointed__EndDateTime__c = appt.Appointed__EndDateTime__c.addSeconds(-1);
}
// Update the records
if (!appointmentsToUpdate.isEmpty()) {
try {
update appointmentsToUpdate;
System.debug('Successfully rolled back ' + appointmentsToUpdate.size() + ' appointment records.');
} catch (DmlException e) {
System.debug('An error occurred while rolling back appointment records: ' + e.getMessage());
for (Integer i = 0; i < e.getNumDml(); i++) {
System.debug('Error on record ' + e.getDmlId(i) + ': ' + e.getDmlMessage(i));
}
}
} else {
System.debug('No appointment records found that meet the criteria for rollback.');
}
Step 5: Revert Flow Changes
-
Open the active "Local Copy Send Appointiv SMS to Clients" flow
-
Navigate to the "Run Immediately" path
-
Edit the "Send Reschedule SMS now?" decision step
-
Change the condition back:
-
From: "{!$Record.Appointed__StartDateTime__c}" "is changed" = False
-
To: "{!$Record.Appointed__StartDateTime__c}" "is changed" = True
-
-
Save and activate the flow
After completing these steps, the new flow should be active and all future appointments should have their reminders set correctly.
Comments
0 comments
Please sign in to leave a comment.