We want to create Salesforce Lightning Custom Object Calendar and make it available for all the sales reps. How do I do it rather than asking each user to create their own.

3 Answers 3


FIrst create a public group with all the Users needed

Then use the below code.If you are looking to use a public calendar you will have to assign the id of public calendar to publisher Id of calendarView that you insert.

Group userGroup = [
    SELECT Id 
    FROM Group 
    WHERE Name = 'Marketing User'//Replace this with name of your public 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 = 'AccountCalendar', 
        SobjectType = 'Investment__c', 
        StartField = 'createddate',
        DisplayField = 'Name', 
        OwnerId = groupMember.UserOrGroupId

insert calendarViews;
  • Notes: 1) that if membership of the public group changes over time, you'll need to add/remove CalendarView records in either one-off or via scheduled job; (2) If sharing object calendars filtered by listviews, you need to include ListViewFilterId as part of the CalendarView construction
    – cropredy
    Commented Jul 2, 2023 at 19:15

Currently, the Salesforce Public Calendars that were referenced by SalesforceMeach above only show Events. The author specified Custom Object calendars, which currently can only be created as private calendars. Through the API and/or custom apex code you can push out a private calendar to any number of users using the CalendarView object. But this is a clunky solution at best because any time you want to make a change, that has to be manually pushed out as well. There is an idea that can be voted on to add sharable custom object calendars as a feature: https://ideas.salesforce.com/s/idea/a0B8W00000GdblHUAR/allow-sharing-of-custom-object-calendars-ideally-as-a-list-view-type


Have you tried using Public Calendars and Resources within Salesforce? You can learn a little more about it here: https://help.salesforce.com/articleView?id=customize_groupcal.htm&type=5

Summarizing the link above: Generating new calendars can be done through setup. Setup -> Public Calendars and Resources -> New. Complete the information requested and make sure to check Active. Then you can update the sharing settings by identifying the roles, users, or groups that have access to this calendar.

Finally, on the Calendar tab in the Lightning Experience, individual users can add the new calendar to their view on the "Other Calendars" section.

Let me know if this answered your question and please mark it correct if so! Thanks.

You must log in to answer this question.

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