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).

  • Pretty sure it is not supported.
    – Adrian Larson
    Commented 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 Commented Feb 21, 2020 at 18:56

2 Answers 2


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>();
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

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.


It seems like the CalendarView object handles some of the sharing functionality of Calendars.

  • To 'subscribe' Users to the "New Public Calendar" - follow the code sample in @nbrown's comment and use PublisherId = newPublicCalendar.Id. You may have to Query the Calendar object to find the Id of the New Public Calendar.
  • To 'unsubscribe' Users from the "Old Public Calendar" - query for CalendarView WHERE PublisherId = :oldPublicCalendar.Id and delete those records

You must log in to answer this question.

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