I need to automate adding Event records to a Public Calendar. Is it possible to do so using Apex? I tried using the OwnerId field, but no luck.

  • Have you tried setting the OwnerId to the public calendar Id (023 keyprefix I think). Try manually creating the required record in the UI, using SOQL to query it, and then replicating the creation of the same record with Apex. Commented Mar 8, 2015 at 23:08
  • 1
    @DanielBallinger Problem is, you don't get to query public calendars. At least, not that I've found. Has something changed?
    – sfdcfox
    Commented Mar 9, 2015 at 9:09
  • 1
    You can't get the public calendar Id easily through Apex. I had to use a custom label with the calendar Id. Is this close to what you are looking for: salesforce.stackexchange.com/questions/55528/… ? Commented Mar 9, 2015 at 17:49
  • @sfdcfox I didn't know they don't show up via SOQL. If you can get the ID from the query string (as Programmable Medley suggests) then it should be possible to create the an Event setting the OwnerId. It does seem odd that you could create them but no query them. Commented Mar 9, 2015 at 19:18

1 Answer 1


The way I have done this in the past is using a Custom Object because we already had existing data there, but it would work equally well with a Custom Setting. The key is just getting the correct Id value and assigning it to OwnerId, as you suspected.

Calendar_Setting__c setting = Calendar_Setting__c.getInstance(CALENDAR_NAME);
if (setting != null) someEvent.OwnerId = setting.CalendarId__c;

You must log in to answer this question.

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