1

I have Salesforce Sites set up with My Domain.

I'm trying to create an Event to be added on a calendar when a Guest user submits a form on a public Visualforce page.

When clicking Save, the "Authorization Required" page shows.

enter image description here

The custom controller:

public class MyEventController {
  public MyEventController() {
  }

  public Datetime AppointmentDate { get; set; }

  public Pagereference Save() {
    Event event = new Event(Subject = 'New Event');
    event.Type = 'Meeting';
    event.Location = '123 main st';
    event.StartDateTime = this.AppointmentDate;
    insert event;
    return null;
  }
}

Events is not one of the objects listed under Standard Object Permissions of the Site Guest User profile. Sharing settings don't appear to allow the Guest user Create permissions, only Read, unless I'm mistaken.

  • Where would I find the Create permissions for the Event object, or
  • What settings do I need to enable

to accomplish inserting an Event as a Guest user?

Thank you

1

Make sure you have Access Activities permission for the guest user profile, this allows you to access the events, tasks, and emails. You can read more about this permission here

Also, the other issue with your code is it does not have endDatetime, so provide that

Event event = new Event(Subject = 'New Event');
event.Type = 'Meeting';
event.Location = '123 main st';
event.StartDateTime = this.AppointmentDate;
event.EndDateTime = this.AppointmentDate + 6;
insert event;

Also, note any error in your apex code will send you to the unauthorized page if that's set as a page for an error in your Site configuration.

Hence make sure to debug the code as a Site user by logging the logs following the instructions in the video shown here

1
  • 1
    This is exactly what I needed, and the debugging instructions. Thank you.
    – T. Webster
    Jul 4 at 17:50
1

You need to grant guest user of your community access to the VisualForce page and the Controller Apex Class. If it is still not working please add details of your community set up including type of community and the URL you are using to access the VisualForce page. Also set the value of the duration field in your controller.

event.DurationInMinutes = 30;

The answer above was from the perspective of communities. However the same applies to sites as well. Please update the public access settings to grant access to the VisualForce page and the Controller Apex Class.

1
  • ty Rajiv. The Guest user already had access to the Visualforce page, and enabling Apex Class access to the custom controller wasn't necessary; I just followed the answer by Mohith.
    – T. Webster
    Jul 4 at 17:48
0

You can't enable activities for Guest Users, as this could expose related records unintentionally. This is locked down on purpose, and you cannot directly circumvent it. The intent is that anyone who needs more than read-only access should log in through some mechanism. This might be a Chatter, Chatter Free, Community, or other low-cost/free license.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.