The infamous Matt Brown threw out a question the other day
After some back and forth with Matt it turned out there are many questions on the Salesforce.com Answers forums related to getting reminders back after a user clicks ‘Dismiss All’ on the reminders pop up. I decided to give this a stab and the following is the result.
I created a Visualforce Page that simply has a button on it along with a disclaimer of what the button will do.
<apex:page controller="resetReminderController" sidebar="false">
<apex:form >
<apex:panelGrid columns="2">
<apex:outputPanel >
<apex:outputText >
<br/><br/>
To reset all of your <b>open</b> task and <b>future</b> event reminders click the button.<br/>
Any open tasks and any future events will have the reminders turned on. <br/><br/>
</apex:outputText>
</apex:outputPanel>
<apex:commandButton value="Reset Reminders" action="{!processItems}"/>
</apex:panelGrid>
</apex:form>
<apex:outputText value="No tasks or events processed" rendered="{!noRecords}" style="color:red"/>
<apex:pageBlock title="Updated Tasks" tabStyle="Task" rendered="{!RenderTasks}" id="theTasks">
<apex:pageBlockTable value="{!updateTaskList}" var="ut">
<apex:column value="{!ut.Subject}"/>
<apex:column value="{!ut.ActivityDate}"/>
<apex:column value="{!ut.IsReminderSet}"/>
<apex:column value="{!ut.ReminderDateTime}"/>
<apex:column value="{!ut.whoId}"/>
<apex:column value="{!ut.whatId}"/>
</apex:pageBlockTable>
</apex:pageBlock>
<apex:pageBlock title="Updated Events" tabStyle="Event" rendered="{!RenderEvents}" id="theEvents">
<apex:pageBlockTable value="{!updateEventList}" var="ue">
<apex:column value="{!ue.Subject}"/>
<apex:column value="{!ue.ActivityDate}"/>
<apex:column value="{!ue.IsReminderSet}"/>
<apex:column value="{!ue.ReminderDateTime}"/>
<apex:column value="{!ue.whoId}"/>
<apex:column value="{!ue.whatId}"/>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:page>
The main purpose of the controller is to query for all open tasks and future events owned by the current user and set the reminder flag to true, allowing them to show up in the reminder pop-up when logging in. The controller will not set the reminder flag for any Tasks that never had a reminder set. We know this because the Reminder Date is null. Had it been set previously, it would still be set; the reminder flag was just unchecked.
public with sharing class resetReminderController {
public List<Task> updateTaskList {get;set;}
public List<Event> updateEventList {get;set;}
public Boolean noRecords {get;set;}
//This is our constructor. initialize the lists and noRecords
public resetReminderController(){
updateTaskList = new List<Task>();
updateEventList = new List<Event>();
noRecords=false;
}
public boolean getRenderTasks(){
return !updateTaskList.IsEmpty();
}
public boolean getRenderEvents(){
return !updateEventList.IsEmpty();
}
public void processItems(){
//make sure the lists are clear
updateTaskList.clear();
updateEventList.clear();
//if there are no records, we want to display that message to the user
noRecords=true;
//loop though users open tasks and update any task with no reminder. if reminder date is null, then reminder was never set in the first place
for(Task t : [select Id, Subject, ActivityDate, ReminderDateTime, IsReminderSet, whoId, whatId from Task where OwnerId = :UserInfo.getUserId() and IsClosed=false]){
if(!t.IsReminderSet && t.ReminderDateTime <> null){
t.IsReminderSet = true;
updateTaskList.add(t);
}
}
//loop through all future events and turn on the reminder. since reminder for events is a picklist, it won't be null. no need to account for that
for(Event e : [select Id, Subject, ActivityDate, ReminderDateTime, IsReminderSet, whoId, whatId from Event where OwnerId = :UserInfo.getUserId() AND (ActivityDateTime >= :DateTime.now() OR ActivityDate >= :Date.Today()) ]){
if(!e.IsReminderSet){
e.IsReminderSet = true;
updateEventList.add(e);
}
}
//update any tasks that were changed
if(!updateTaskList.IsEmpty()){
update updateTaskList;
noRecords=false;
}
//update any events that were changed
if(!updateEventList.IsEmpty()){
update updateEventList;
noRecords=false;
}
}
}
Finally, I created a very simply home page component with a link to the visualforce page. The component name is “Reset Reminders For My Open Tasks and Event” and the html (be sure to check the ‘show html’ checkbox) is:
<a href="/apex/resetReminders">Click here</a> to reset the reminders for tasks and events.<div><br></div>
I figured the easiest way to show the functionality was with a quick demo.
Finally, you can install an unmanaged package of the home page component (don’t forget to add it to a page layout), visualforce page, controller and test method with this link:
https://login.salesforce.com/packaging/installPackage.apexp?p0=04tE00000000RkA
*Remember, you can change the path to https://test.salesforce.com… to install to a sandbox.
