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
Lee EngelhardtLee Engelhardt 

Authorization Required Problem on Simple Public Page

Alright, I'm sure this just has to do with me being very new to Salesforce coding and sites and not knowing what I'm doing but I've beaten my head against this rock enough and beg the wisdom of those more experianced.

I'm making a very simple public page. I'm not even using a custom controller, just the standard contact one.  The premise is that the contact will have recieved an email asking for their permission to send them some information about services.  The email will have a link to my page with the contact id in the url (?id=<the id number>).  The form lets them see their email address on record and check a box to give us permission to email them more.  They click submit, the info gets saved and they get a thank you page.  Thats it, and it works flawlesly when I'm logged in, and it looks fine when I open the page as an anonymous user and don't give it a contact id to work with, however, the moment I put in a contact id when viewing anonymously, I get the Authorization Required page.

<apex:page standardController="Contact" sidebar="false" showHeader="false">
    <div style="width:500px; margin-top:100px; margin-left:auto; margin-right:auto;">
    <apex:pageBlock >
        <h1>Thank you for your interest!</h1><br />
        <p>Please check the box below and click submit to recieve further information.</p><br />
        <apex:pagemessages />
        <apex:form >
        <apex:actionFunction name="saveAndThanks" action="{!Save}" oncomplete="window.parent.location.href='http://abstraktmg.force.com/emailoptin/Email_OptIn_ThankYou'"/>
        <p>Your Email:</p>
        <apex:inputField value="{!Contact.Email}" /><br/>
        <apex:inputCheckbox value="{!Contact.Email_Opt_In__c}"/>I want to know more.<br />
        <apex:CommandButton onClick="saveAndThanks();" value="Submit" />
        </apex:form>
    </apex:pageBlock>
    </div>
</apex:page>
I've tried a lot of the normal debugging advice but since it only gets the error when an id is added, I'm kind of stuck since most of the debugs, like "Preview as Admin" don't seem to run properly with a url argument included.  I did get the guest account added for monitoring but the log doesn't seem to be generating anything usefull.

31.0 APEX_CODE,DEBUG;APEX_PROFILING,INFO;CALLOUT,INFO;DB,INFO;SYSTEM,DEBUG;VALIDATION,INFO;VISUALFORCE,INFO;WORKFLOW,INFO
19:41:15.077 (77125771)|EXECUTION_STARTED
19:41:15.077 (77165945)|CODE_UNIT_STARTED|[EXTERNAL]|066G0000002LFVU|VF: /apex/Email_OptIn
19:41:15.077 (77189102)|CODE_UNIT_STARTED|[EXTERNAL]|VF Controller Save
19:41:15.077 (77213288)|CODE_UNIT_FINISHED|VF Controller Save
19:41:15.946 (189796502)|CUMULATIVE_LIMIT_USAGE
19:41:15.946|LIMIT_USAGE_FOR_NS|(default)|
  Number of SOQL queries: 0 out of 100
  Number of query rows: 0 out of 50000
  Number of SOSL queries: 0 out of 20
  Number of DML statements: 0 out of 150
  Number of DML rows: 0 out of 10000
  Maximum CPU time: 0 out of 10000
  Maximum heap size: 0 out of 6000000
  Number of callouts: 0 out of 10
  Number of Email Invocations: 0 out of 10
  Number of future calls: 0 out of 10
  Number of Mobile Apex push calls: 0 out of 10

19:41:15.946|CUMULATIVE_LIMIT_USAGE_END

19:41:15.189 (189846151)|CODE_UNIT_FINISHED|VF: /apex/Email_OptIn
19:41:15.191 (191580457)|EXECUTION_FINISHED

Any and all help is much appreciated.  Thank you.

Deepak RamaDeepak Rama

Is this page authorized for the portal/site? In the site configuration, you have to set the page to be visible to the user without authorization. For more information - please read : https://help.salesforce.com/htviewhelpdoc?id=sites_managing_sites.htm&siteLang=en_US (https://help.salesforce.com/htviewhelpdoc?id=sites_managing_sites.htm&siteLang=en_US)


Also please note that you have to give access to the objects and fields that are being exposed to pages used in sites that do not require authentication.

Lee EngelhardtLee Engelhardt
Yes this is a Force.com site that I have created per that links bethod, as noted, the page loads 100% fine when logged out and WITHOUT the Contact ID appended to the url, its only when I add the url that I have problems.(Does that sound like I'm covered and not missing something silly for your first part?)

As for field access. The only information that I am presenting, as can be seen in the code is the email field and a custom email opt-in field that both exist on the contact record.  Under Object Settings -> Contacts I have enabled Read & Create for both the Contact object as well as the 2 fields.  I'm not using a custom controller so nothing to do there. Anything I'm missing?
Lee EngelhardtLee Engelhardt
And just to reiterate what I mean about the details of the error.  When logged out and thus viewing as a public user.

http://mydomain.force.com/emailoptin  <--  Displays fine, though since its not pointed at a contact it doesn't really do anything and the fields are empty and

http://mydomain.force.com/emailoptin?id=003G000001FxYCC <-- Authentication Error
Lee EngelhardtLee Engelhardt
Sorry misread the start of your first post, and yes the visualforce page is in the list of authorized pages on the site, the site is entirely for this project right now so its the homepage.  Really wish there was an edit option in these forums.