2

I am looking into the new chatter feature in Winter '18 which is Out of Office, I have the custom component handling Out of Office for the approval process functionalities etc and I wanted to connect that to the new chatter feature, but I cannot seem to find the fields that are associated with it.

Namely you can set Start Date, End Date, Out Of Office and an Out of Office message on the User's record, but on the User sObject fields I cannot seem to see any fields related to that except for OutOfOfficeMessage field which contains the message.

Does anyone know where can I retrieve the other fields from?

0

1 Answer 1

12

Going through objects in Workbench, I found an object named OutOfOffice which is also accessible from apex.

Query-

SELECT StartDate, EndDate, Id ,IsEnabled, Message, UserId FROM OutOfOffice

Here is a utility class to handle out of office for a user:

public class OutOfOfficeHelper {
    public static void set(Id userId, String message, Date startDate, Date endDate) {
        // extract existing record
        Id outOfOfficeId;
        for(OutOfOffice o: [SELECT Id FROM OutOfOffice WHERE UserId = :userId]) {
            outOfOfficeId = o.Id;
        }
        upsert new OutOfOffice(
            Id = outOfOfficeId,
            UserId = userId,
            IsEnabled = true,
            StartDate=startDate,
            EndDate=endDate,
            message=message);
    }
    public static void reset(Id userId) {
        delete [SELECT Id FROM OutOfOffice WHERE UserId = :userId];
    }
}

Note: OutOfOffice object is only available when Users can set Out of Office messages setting is turned on.

1
  • Thank you very much! That is what I was missing, didn't know they created an object for it since documentation stated that is on the user preferences.
    – Paul
    Oct 20, 2017 at 9:28

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .