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
Suveer MohunlalSuveer Mohunlal 

Visualforce page not saving guest site user data to custom object

Hi guys,

Im having trouble getting my visualforce page to save data to my custom object. Im working in sandbox and using sites to expose my page publicly to get input from guest users. It works when I enter data from the preview but not when I open the link. I have checked my 'Public Access Settings' and gave the correct permissions for Org, Object and Field level security. I've tried everything from related posts but nothing seems to work.

Here is my code:

Visualforce page:
 
<apex:page standardStylesheets="false" sidebar="false" showHeader="false" standardController="Candidate__c" extensions="MyCandidateController">
<apex:form style="font:poppins;">
 
<apex:pageBlock >

        <center> <apex:image url="{!$Resource.Khono}" width="375" height="92"/> </center>
        <apex:styleSheet value="{!$Resource.Khonology_CSS_Style}"/>
        <apex:styleSheet value="{!$Resource.Khono_Font_Style}"/>
        <apex:styleSheet value="{!$Resource.Khono_Button_Style}"/>
        <apex:styleSheet value="{!$Resource.Khono_All_Min_Style}"/>


 <form id="contact-form">  
        <apex:pageBlockSection title="Personal Information">


            <apex:pageBlockSectionItem >
                
                <apex:inputfield html-placeholder="First Name" id="Name" value="{!c.Name}" />
            </apex:pageBlockSectionItem>
    
             <apex:pageBlockSectionItem >
                
                <apex:inputfield html-placeholder="Last Name" id="Surname" value="{!c.Surname__c}" />
            </apex:pageBlockSectionItem>
    
            <apex:pageBlockSectionItem >
               <apex:outputLabel ><th><td>Gender</td></th></apex:outputLabel>
                <apex:inputField html-placeholder="Gender" id="Gender" value="{!c.Gender__c}" />
            </apex:pageBlockSectionItem>
    
            <apex:pageBlockSectionItem >
                <apex:outputLabel ><th><td>Ethnicity</td></th></apex:outputLabel>
                <apex:inputField id="Ethnicity" value="{!c.Ethnicity__c}" />
            </apex:pageBlockSectionItem>
    
            <apex:pageBlockSectionItem >
                <apex:outputLabel ><th><td>Country of Birth</td></th></apex:outputLabel>
                <apex:inputField id="COB" value="{!c.Country_of_Birth__c}" />
            </apex:pageBlockSectionItem>
    
            <apex:pageBlockSectionItem >
               
                <apex:inputField html-placeholder="ID Number" id="IDno" value="{!c.ID_Number__c}" />
            </apex:pageBlockSectionItem>
    
            <apex:pageBlockSectionItem >
                
                <apex:inputField html-placeholder="Email" id="Email" value="{!c.Email_Address__c}"/>
            </apex:pageBlockSectionItem>
    
            <apex:pageBlockSectionItem >
               
                <apex:inputField html-placeholder="Contact Number" id="ContactNo" value="{!c.Contact_Number__c}" />
            </apex:pageBlockSectionItem>
    
            <apex:pageBlockSectionItem >
                <apex:outputLabel ><th><td>Residential Address Province</td></th></apex:outputLabel>
                <apex:inputField id="Province" value="{!c.Residential_Address_Province__c}" />
            </apex:pageBlockSectionItem>
    
</apex:pageBlockSection>

<apex:pageBlockSection title="Qualification">    

    
            <apex:pageBlockSectionItem >
                <apex:outputLabel >University</apex:outputLabel>
                <apex:inputField id="Uni" value="{!c.University__c}" />
            </apex:pageBlockSectionItem>
    
            <apex:pageBlockSectionItem >
                <apex:outputLabel >Qualification</apex:outputLabel>
                <apex:inputField id="Qualification" value="{!c.Qualification__c}" />
            </apex:pageBlockSectionItem>
    
            <apex:pageBlockSectionItem >
                
                <apex:inputField html-placeholder="Major Subjects" id="Subjects" value="{!c.Major_Subjects__c}" />
            </apex:pageBlockSectionItem>
   
</apex:pageBlockSection>
 </form>    


    <apex:pageBlockButtons >    
        <apex:commandButton id="Save" action="{!Save}" value="Save" styleClass="btn .btn-primary"/>
        <apex:commandButton id="Cancel" action="{!Cancel}" value="Cancel" styleClass="btn .btn-primary"/>
    </apex:pageBlockButtons>



</apex:pageBlock>

    
</apex:form>
</apex:page>






Controller:
 
public without sharing class MyCandidateController {
   
   
    public Candidate__c c { get; set; }
    
    public MyCandidateController(){
        c=new Candidate__c();      
    }

    
    public MyCandidateController(ApexPages.StandardController con){
       c=new Candidate__c();
    
    }

    public PageReference save() {
       insert c;  
        PageReference pr=new PageReference('/apex/CandidateConfirmation');
        pr.setRedirect(true);
   
      return pr;
    }


   }





 
Gyanender SinghGyanender Singh
Hi Suveer,

Have you tested to insert record by using the vf page.
And in the Public access setting have you inserted both Apex class and vf page and permission of all fields that you are using the page and in the class.

Regards,
Gyani
Suveer MohunlalSuveer Mohunlal
Yes Gyanender,

I have tested the VF page while logged in and out. The org picks up the site guest user in the log but the data does not get written to the custom object.

User-added image
And with the Public Access Settings I have ensured all are in order as you can have a look below:
User-added image

User-added image

User-added image

Im not sure if it could be a problem with the apex code or visualforce code? What do you think?

Thank You.