“My Calendar” Create via flow or apex

calendardevelopervisual-workflow

I contacted salesforce support but they just told me that it's possible.

I would like to ask if there is a way to create "My Calendars" via flow or process builder. Because these are the created by every user and it's for them only. I don't want to make every user create 10/15 calendars so i would like to do it another way like flow. Using my calendar we are able to select a colour for each calendar which help our users a lot.

Best Answer

I am not so sure about Flows. It may be necessary to use an invokable Apex action in conjunction with a Flow. However this is possible with Apex. Look into the CalendarView metadata type. The example code is taken from the example provided by Salesforce on that page. What it does is creates a new CalendarView and assigns it to users within the "Sales Group". This can be modified to meet your needs.

Group userGroup = [
    SELECT Id 
    FROM Group 
    WHERE Name = 'Sales Group' 
    LIMIT 1
];
List<Id> groupId = new List<Id>{userGroup.id};

List<GroupMember> groupMembers = [
   SELECT UserOrGroupId 
   FROM GroupMember
   WHERE GroupId IN: groupId
];

List<CalendarView> calendarViews = new List<CalendarView>();
for (GroupMember groupMember : groupMembers) {
    CalendarView calendarView = new CalendarView(
        name = 'Opportunity Close Dates', 
        SobjectType = 'Opportunity', 
        StartField = 'CloseDate', 
        DisplayField = 'Name', 
        OwnerId = groupMember.UserOrGroupId
    );
    calendarViews.add(calendarView);
}

insert calendarViews;
Related Topic