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
Tyler HarrisTyler Harris 

Public Site/Visualforce Page won't let a guest user submit data

My visualforce page on my Public Site will not allow a guest user to submit data to my salesforce instance. Once I hit submit it throws a "authorization is required" page.


Visualforce:
<apex:page standardController="Lead" standardStylesheets="true" sidebar="false" cache="true" showHeader="false" showChat="false" >
    <apex:pageBlock title="Do You Love Me?">
        <apex:pageBlockSection >
            <apex:pageBlockSectionItem >
   
            <apex:form >
                <apex:pageBlock mode="edit" >
                    <apex:pageBlockSection >
                <apex:inputText value="{!Lead.FirstName}" label="First Name"/>
                <apex:inputText value="{!Lead.LastName}" label="Last Name"/>
                <apex:inputText value="{!Lead.Email}" label="Email Address"/>
                <apex:inputText value="{!Lead.Company}" label="Where you work?"/>
                <apex:inputCheckbox value="{!Lead.Love_Your_Hubby__c}"/>
                    </apex:pageBlockSection>
                </apex:pageBlock>
                <apex:commandButton action="{!Save}" value="Let me know how you feel"/>
            </apex:form>
            </apex:pageBlockSectionItem>
        </apex:pageBlockSection>
    </apex:pageBlock>
    <apex:pagemessages escape="true" rendered="true"></apex:pagemessages>
</apex:page>
Andy BoettcherAndy Boettcher
You need to hit the "Public Access Settings" button within your site and assign the Guest user for your site permissions to create leads (similar to profile or permission set) in your instance.
Tyler HarrisTyler Harris
That's already enabled. It's still not letting me submit.
User-added image
Andy BoettcherAndy Boettcher
That is your object setting (half of the battle).  You need to check field-level security as well as if the guest user has access to the VF page and Apex class too.

Barring that, in the Site - hit the "Preview as Admin" link and see if you can get some more detail on that error...or you can also do the "Debug Log" as the Guest user to get more information that way too.
Tyler HarrisTyler Harris
Yea it's throwing an error system.security.NoAccessException: Create access denied Lead. I'm not sure how to fix.
Andy BoettcherAndy Boettcher
Random question - if you're just creating a simple lead, why not just use Web To Lead?  Why the overhead of Sites?
Tyler HarrisTyler Harris
Totally logical question, but in this case, I'm using this as a learning project. This is literally the last portion I need to fix.

I got two corresponding triggers that are firing before insert and after insert when a lead hits the system.

Trying to get more familiar with the system and sites in general.
Tyler HarrisTyler Harris
Say for instance I wanted to create a simple app that I can expose to a public audience. I want them to have a limited set of CRUD abilities and then redirect them to a thank you page. That's essentially what I'm trying to do here. I've gotten the code to redirect to a Thank You Page worked out, but this permissions part has me stuck.
alexander yurpolskyalexander yurpolsky
have the same error here does anyone have a solution