1

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?

9

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.

| improve this answer | |
  • 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 '17 at 9:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.