2

With the release of Public Calendars in Lightning this update, we are moving a central calendar for our Sales users from a specific user over to a Public Calendar.

We would like to seamlessly move any users subscribed to the original User calendar over to the new Public Calendar, but thus far I've found no way to either query users who are subscribed to a specific calendar nor to use Apex to subscribe users to the new calendar.

Anyone have success with this before?


To add to this, I've looked into the newly introduced CalendarView object (potentially using it to subscribe users to the Event object somehow) but this isn't quite what I need. This function creates new subscriptions to Objects for users, where I simply want a script / Apex code to actually add a Public Calendar to a User's view of Calendars (while removing their current subscription to the old User-based calendar).

2
  • Pretty sure it is not supported.
    – Adrian Larson
    Feb 21, 2020 at 18:18
  • @AdrianLarson I'm feeling like this might be the case, unfortunately. Hoping someone might have a roundabout way to accomplish, but hopes aren't high Feb 21, 2020 at 18:56

1 Answer 1

0

The CalendarView object documentation displays a code sample that shows "sharing" a calendar by assigning ownership to a group, user list, or profile. You can get close to what you hope to achieve by using a group, user list, or profile to give the calendars you want with a large set (or nearly all by using a group like "All Internal Users") of users at one time.

This will make the calendar appear on all of the users' calendar apps automatically which it sounds like is what you're most interested in, even though this is not, strictly speaking, a Salesforce Public Calendar.

CalendarView example using Group:

Group userGroup = [
    SELECT Id 
    FROM Group 
    WHERE Name = 'Sales Group' 
    LIMIT 1
];
List<Id> groupId = new List<Id>();
groupId.add(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;

I checked and triggers are not allowed on CalendarView and it's not listed as an object under Sharing Settings either so using a trigger to automate sharing isn't feasible and neither are sharing rules. Over time, I imagine CalendarViews become easier to work with like other objects or the Calendar app itself can become more configurable so that the users are automatically viewing certain Public or Resource Calendars.

As you discovered, with a Public Calendar (a Calendar object where Type = Public) you can create it and have users access it without code, however there's a step each user would need to take to add it to their Calendar app view. It's also not possible to remove a user's personal calendar as the IsActive field is not writeable on them.

You must log in to answer this question.

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