function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
The FinnsterThe Finnster 

How to Create Object Calendars from the API

Hi,

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

https://developer.salesforce.com/docs/atlas.en-us.224.0.object_reference.meta/object_reference/sforce_api_objects_calendarview.htm

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) 
Hi,

Greetings!

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

https://developer.salesforce.com/docs/atlas.en-us.object_reference.meta/object_reference/sforce_api_objects_calendar.htm

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,

Finn