Apex update default event reminders Salesforce

Changing Default Event Reminders in Users Settings For Multiple Users

Updating the “Set default event reminders to” or any other User Setting for multiple Users.

 

Scenario:

While creating an Event or Task in Salesforce, the “Reminder” Checkbox is checked by default for all users. The reminders have piled up and making it difficult to keep track of the important events and tasks. The Sales team wants you to uncheck the “Set default event reminders to” Checkbox for all users.

This setting is found in:
My Settings >> Calendar and Reminders >> Activity Reminders >> ‘Set default event reminders to’

Activity Reminders Salesforce
Activity Reminders Salesforce
Activity Reminder Settings Salesforce
Activity Reminder Settings Salesforce

 

Solution:

This can be achieved by updating the User Object using Apex Code or the Data Loader

Executing Apex Code Method

A simple Apex code snipped can help us in unchecking “Set default event reminders to” Checkbox for multiple users. We will be using the Developer Console’s Execute Anonymous Window to run the Apex code.

To “Set default event reminders to” Checkbox to Unchecked, our Apex code will perform the following steps:

  1. Step 1: Create a List to hold Users that need an update to their settings.
  2. Step 2: Find all Active Users whose ‘Activity Reminder Checkbox’ is ‘Checked’ and add them to the above list.
  3. Step 3: Iterate through each user in the above list and Uncheck the Activity Reminder Checkbox
  4. Step 4: Create a final list to update to reduce the DML statements

We will create a List of Users

// Create a list of Users whose setting needs to be changed
List <User> userList = New List <User>();

 

We then write an SOQL to fetch all the users whose settings have to be changed.

//SOQL to add all users to the above list
userList = [
    SELECT Id, UserPreferencesEventRemindersCheckboxDefault
    FROM User
    WHERE UserPreferencesEventRemindersCheckboxDefault = True AND ISACTIVE = True];

 

In this step, we will iterate through each user and change the required settings. Refer to the developer guide to know more about the settings. We will also add the users to the final list to be updated.

// Iterate through each user and update the setting
For (User u:userList) {
    u.UserPreferencesEventRemindersCheckboxDefault = False;
    userList2update.add(u);  //Add user to the final list to update
}

 

As a best practice to reduce the DML statements, we will add the User to another list named ‘userList2Update’. Then, update all the Users in this list together using DML.

//Create a final list of Users to perform DML
List <User> userList2Update = New List <User>();


update userList2Update;  //Update the final List

 

Here’s the complete code to uncheck the “Set Default Reminders to” or any other user setting in Salesforce.

//Create a final list of Users to perform DML
List <User> userList2Update = New List <User>();
// Create a list of Users whose setting needs to be changed
List <User> userList = New List <User>();

//SOQL to add all users to the above list
userList = [
    SELECT Id, UserPreferencesEventRemindersCheckboxDefault
    FROM User
    WHERE UserPreferencesEventRemindersCheckboxDefault = True AND ISACTIVE = True];

// Iterate through each user and update the setting
For (User u:userList) {
    u.UserPreferencesEventRemindersCheckboxDefault = False;
    userList2update.add(u);  //Add user to the final list to update
}

update userList2Update;  //Update the final List

 

Now that we have the Apex Code, lets head to the Developer Console and execute this code from the Anonymous Window (Ctrl + E)

 

For the Data Loader method, please visit the Salesforce Help Article
https://help.salesforce.com/articleView?id=000004609&language=en_US&type=1

For a complete list of fields on the User Object, please visit the Developer Guide
https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_objects_user.htm

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.