0

I have a public calendar that is shared with a public group. An observation I've made is that you have to manually add a calendar that has been shared with you. It doesn't automatically appear on your calendar. Is there a way to fulfill this programmatically via apex?

I'm able to query all the public calendars and get the id using the following query :

Select Id,Name From Calendar Where Type='Public'

The part I'm stuck at is how I can add this public calendar on my own calendar WITHOUT needing to manually add the calendar.

2 Answers 2

0

This is currently not possible, i had the same requirement and tried few methods but could not make it happen.

It is possible to use the CalendarView object to create a Calendar based on an SObject and assign it to a particular Salesforce User. But you can't do the same for Public & Resource Calendars.

I have found an Idea that is talking about the same feature, so you might promote in order to get the feature in a future release, here is the link

0

you have to assign the Id of the public calendar to the PublisherId of the CalendarView that is to be inserted.

    Group userGroup = [
      SELECT Id 
      FROM Group 
      WHERE Name = 'Marketing User' 
      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 = 'TestingPubl', 
             SobjectType = 'Event', 
             StartField = 'StartDateTime',
             DisplayField = 'Subject', 
             OwnerId = groupMember.UserOrGroupId,
             publisherId = '023040000006uhfAAA'//This is the Id that we get from 
                                              //SELECT Id FROM Calendar
             );
     calendarViews.add(calendarView);
     }  

     insert calendarViews;

You must log in to answer this question.

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