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
alexander yurpolskyalexander yurpolsky 

Salesforce: Creating a User Form using VisualFocre

I have below requirement to Create a VF page. I created a custom object called DormsApplicants__c There are several fields but for the purposes of the example we will use only one field called First_name__c.

My main need is to create a VF page that will be available to people outside the organization (i.e. customers) who can enter data into the form and then create a record in the custom object DormsApplicants__c. For this purpose I created a website (SITE.COM) and then created a VF page (called TEST) I defined this page (TEST) as a home page on the site.

This is my page:
 
<apex:page standardController="DormsApplicants__c" sidebar="false">
<apex:form id="theForm">
<apex:pageBlock title="TEST">
    <apex:inputText title="TEXTBOX1" label="TEXTBOX2"  value="{!DormsApplicants__c.First_name__c}"/>
    <apex:commandButton value="save" action="{!save}"/>
    </apex:pageBlock>
</apex:form>


 This is what users see outside the organization.

This is what users see outside the organization.

When the user tries to click "save" he gets the following error
User-added image

Of course no record is created. I'd love to hear what the problem is?
Raj VakatiRaj Vakati
All pages that you want to expose on a site must be associated with that site. If a page is not listed under Site Visualforce Pages, an authentication or page-not-found error is displayed based on the existence of the page.

To enable Visualforce pages for your site:
From Setup, enter Sites in the Quick Find box, then select Sites.
Click the name of the site you want to modify.
Click Edit on the Site Visualforce Pages related list.
Use the Add and Remove buttons to enable or disable Visualforce pages for your site.
Click Save.


Grant Visualforce page access to the Customer Portal or site user's profile.
Om PrakashOm Prakash
Hi Alexander,
As you are able to view the page and save button it means all required site permissions are already there.
Record was not created means any exception was occurrd. It may be due to validation rule or process builder failure.
You need to troubleshoot it after disabling any process builder on this object.

If record created;
(If record will save then you will get another issue on site, because after record insertion by standard save action, page will redirect to related record id on site, In this case I suggest to use custom save action for site base functionality)
alexander yurpolskyalexander yurpolsky
Thanks for your replay.

As for Raj V suggestions of - I did all the steps and it did not solve the problem.

Just to be clear regarding the problem. The record  is not created. So @Om Prakash how can i to "troubleshoot". I have no processes/wf on the object. A simple object with only one required field. 

Thanks for the help.
 
alexander yurpolskyalexander yurpolsky
Only for  the purposes of  testing I create a new VF page. 
Add to my site https://ibb.co/i5Ey5H
Then I  opened the site (the new specific page I created while I'm not  logon to salesforce)  https://ibb.co/ciJEec  I could see the page even when I was not logged in.  I entered a value into a text box and click "Save"
Then I get a permission error https://ibb.co/i9MBQH

The recored is not created. What's the problem now?




 
Om PrakashOm Prakash

Please check the url in browser when you get authentication  error after save button click.
There should be be a record id after your site url in browser and record was created.
alexander yurpolskyalexander yurpolsky
This is the URL I get: http://XXXX.force.com/a000Y00000mEw30
Now, if you mean That this the ID of the record - a000Y00000mEw30
I can not find it in the system. And its a appear  that the record did not  created successfully.
Om PrakashOm Prakash
Yes that was the record id which was created.
Can you open that record directly by pasting record id in browser's after standard salesforce instance url. (Not on site)
You might be not able to see that record in list view if list view was configured only to show current login user's record in salesforce .
Here created record's owner was Guest user.
 
alexander yurpolskyalexander yurpolsky
@Om Prakash - Thank you ! You were absolutely right!

But now, how do I present my user with a normal message? For example "Your form has been successfully submitted" or something like that. Instead of the authorizationmessage?
Om PrakashOm Prakash
Please try bellow code, I have added  script in your VF page code for the same.
Also I have replaced save action with quicksave, so that page will not redirect and your use case can achieve. 
<apex:page standardController="DormsApplicants__c" sidebar="false">
<apex:form id="theForm">
    <apex:pageBlock title="TEST">
    <div id ="MessagePanel" style="color:green;font-weight:bold;"> </div>
    <apex:inputText title="TEXTBOX1" label="TEXTBOX2"  value="{!DormsApplicants__c.First_name__c}"/>
    <apex:commandButton value="save" action="{!quicksave}" oncomplete="notify();" />
    </apex:pageBlock>
    
     <script>
      function notify(){
       document.getElementById("MessagePanel").innerHTML = "Your form has been successfully submitted";
      }
     </script>  
</apex:form>
</apex:page>