//Create a chatter group
CollaborationGroup gp = new CollaborationGroup();
gp.Name = 'Test Group';
gp.CollaborationType = 'Public';//It can be 'Public' or 'Private'
//Add member to above created chatter group
CollaborationGroupMember gpMember = new CollaborationGroupMember();
gpMember.MemberId = userId;//User id which you want to add
gpMember.CollaborationGroupId = gp.Id;//Above created group id
From Setup enter “Chatter Settings” in the Quick Find box
Select “Chatter Settings”
Check “Users can set Out of Office messages”
Set an Out of Office Message in Chatter:
Open your profile
In your profile page, click on “Out of Office”.
Enable Set Out of Office message.
Select the start date for the time you’ll be out of the office. The start date is just to let people know when you’ll be out. The message starts showing up next to your name as soon as you save it. It doesn’t wait for the start date.
Select the end date. Your message expires after the end date.