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
RetreeverRetreever 

Visualforce page to create records for custom object from Force.com site NOT working!!!

Ok, so I successfully got a VF Page Form to show on my Force.com site , anyone can go to the URL and see the form , even fill it in BUT when you hit "Save" you get the following error message: "Authorization Required-You must first log in or register before accessing this page.If you have forgotten your password, click Forgot Password to reset it."

I have confirmed the guest user permissions are set properly on the Custom Object and in the OWD settings , I have been researching , reading and watching videos for the last week but I have been unable to determine what the problem is. Attached is the code for the VF page.

I think it's something to do with using "standardController" maybe I need a custom controller to make this work - anyone have any suggestions?
<apex:page standardController="Loyalty_Program_Member__c">
<apex:messages />
    <apex:form id="changeStatusForm">
        <apex:pageBlock >
          <apex:pageblocksection title="Loyalty Program Member Detail">
               <apex:inputfield value="{!Loyalty_Program_Member__c.First_Name__c}"/>
               <apex:inputfield value="{!Loyalty_Program_Member__c.Last_Name__c}"/>
               <apex:inputfield value="{!Loyalty_Program_Member__c.Full_Name__c}"/>
               <apex:inputfield value="{!Loyalty_Program_Member__c.Street_Address__c}"/>
        <apex:inputfield value="{!Loyalty_Program_Member__c.City__c}"/>
               <apex:inputfield value="{!Loyalty_Program_Member__c.Province_State__c}"/>
               <apex:inputfield value="{!Loyalty_Program_Member__c.Country__c}"/>
               <apex:inputfield value="{!Loyalty_Program_Member__c.Postal_Zip__c}"/>
        <apex:inputfield value="{!Loyalty_Program_Member__c.Home_Phone__c}"/>
               <apex:inputfield value="{!Loyalty_Program_Member__c.Mobile__c}"/>
               <apex:inputfield value="{!Loyalty_Program_Member__c.Email__c}"/>
               <apex:inputfield value="{!Loyalty_Program_Member__c.Type_of_Pet__c}"/>
        <apex:inputfield value="{!Loyalty_Program_Member__c.Product_Purchased__c}"/>
        </apex:pageblocksection>
        <apex:pageblocksection title="Retailer Information">
             <apex:inputfield value="{!Loyalty_Program_Member__c.Retailer_Name__c}"/>
             <apex:inputfield value="{!Loyalty_Program_Member__c.Retailer_Address_Street__c}"/>
        <apex:inputfield value="{!Loyalty_Program_Member__c.Retailer_Address_City__c}"/>
               <apex:inputfield value="{!Loyalty_Program_Member__c.Retailer_Address_State_Province__c}"/>
               <apex:inputfield value="{!Loyalty_Program_Member__c.Retailer_Address_Country__c}"/>
               <apex:inputfield value="{!Loyalty_Program_Member__c.Retailer_Address_Postal_Zip__c}"/>
        <apex:inputfield value="{!Loyalty_Program_Member__c.Retailer_Phone__c}"/>
               <apex:inputfield value="{!Loyalty_Program_Member__c.Retailer_Fax__c}"/>
               <apex:inputfield value="{!Loyalty_Program_Member__c.Retailer_Email__c}"/>
        </apex:pageblocksection>
        <apex:pageBlockButtons >
             <apex:commandButton value="Save" action="{!save}"/>
        </apex:pageBlockButtons>
       </apex:pageBlock>
    </apex:form>
</apex:page>

Thanks, Roger
Abhishek_DEOAbhishek_DEO
Have you added the controller class "Loyalty_Program_Member__c" and VF page on force.com site guest user profile ?
Roger Bannister 21Roger Bannister 21
Abhi, I think you may be on to something , I did add the VF page on the Force.com site to the guest user profile but I don't have a controller class "Loyalty_Program_Member__c" , do I have to create one? What would it look like? Any help would be greatly appreciated.

Thanks, Roger
Abhishek_DEOAbhishek_DEO

Sorry for late reply!!

As you are using only standard controller, it is fine to add only VF page. It will be hard to say(assuming all the permissions are there) what could be the issue, however, you can follow following steps for troubleshooting

1. remove all field refernce from VF page except "<apex:inputfield value="{!Loyalty_Program_Member__c.First_Name__c}"/>" // just to check if it is happening due FLS seurity - see if it works
2. if not enable debug log for site user to see if logs shows any relevant information.

DineshGuptaDineshGupta
I have faced the same issue but it got resolved when I replaced the standard controller with a custom controller..
Roger Bannister 21Roger Bannister 21
Thanks Dinesh, I had the same thought but don't have the skills to create a custom controller , I tried using someone elses template but couldn't get that right.
Abhishek_DEOAbhishek_DEO
With customer controller it get resolved because code will run in system context. However, with all appropriate permission then it should workd with standrad controller.

As I mentioned, you need to debug it using debug log. There is a very nice blog regarding this error, you may look into this.

http://www.tgerm.com/2010/10/debugging-sites-authorization-required.html