+ Start a Discussion
The FinnsterThe Finnster 

How to Create Object Calendars from the API


I have found this Spring 20 release where we can create object based callendars and share them to public groups.


There is also a code snippet at the bottom of the article but I am not sure on how to use it.

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;

Can anyone please tell me on how to setup the CalendarView using code?
ShirishaShirisha (Salesforce Developers) 


We can't create the records using Calendar Object and the create() call is not supported as mentioned in the below doc:


Kindly mark it as best answer if it helps so that it can help others in the future.

Warm Regards,
Shirisha Pathuri
The FinnsterThe Finnster
Hi Shirisha,

I do not want to create any records using a calendar object. I only want to share an object based calendar with a public group as shown in the code snippet. How to I do that?

Kind Regards,