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
Art and Justice LeagueArt and Justice League 

How to save a custom object custom fileds in a visualforce page?

We are trying to make a simple employment application with visualforce.

 

We created a custom object for employment application, and made a page and site.

 

The problem is, when I publically insert the data and try to save it—the form directs me to that particular record only signed in  users can see—so the public user will get an error page that says the public user don't have access to that certain page.

 

Here is our simple apex code:

 

<apex:page sidebar="false" showHeader="false" standardController="Staff_Application__c">
<div style="margin: 0 auto; padding: 30px; width: 500px;">
<apex:form >
<label>First Name:</label>
<apex:inputField value="{!Staff_Application__c.First_Name__c}" />
<label>Last Name:</label>
<apex:inputField value="{!Staff_Application__c.Last_Name__c}" />
<apex:commandButton value="Save" action="{!save}" />
</apex:form>
</div>
</apex:page>

 

and here is a link to our application:

http://artandjustice.force.com/employment

 

How can a public user press save button and it directs the public user to a page that I want them to see after they press them?  

 

For example after they insert the data, I want them to go to artandjustice.org/confirmation.php?

Best Answer chosen by Admin (Salesforce Developers) 
Alok_NagarroAlok_Nagarro

Hi,

 

Since you are using force.com site and in site you can only access visualforce page. Hence in your page u are using standard controller as well as save method and save method of standard controller redirect u to object's record page that is not visualforce page and you cant access that using site.

 

So wat you need to do, just override the save method. First u need to create extension class and in this class override the save method. Sample code is as given below:

 

Public class MyExtension

{

 Staff_Application__c staff;

public MyExtension(ApexPages.standardController con)

{

 staff=(Staff_Application__c)con.gerRecord();

}

 

public PageReference save()

{

if(staff!=null)

insert staff;

 

PageReference pr=new PageReference(PAGE_URL);

// if you want to redirect to any VF page then PAGE_URL will be = '/apex/pagename';

// and you want to redirect to any external site page the provide full qualified url

pr.setRedirect(true);

return pr;

}

}

 

And add this class as extension in your page:

 

<apex:page sidebar="false" showHeader="false" standardController="Staff_Application__c" extensions="MyExtension">

All Answers

Alok_NagarroAlok_Nagarro

Hi,

 

Since you are using force.com site and in site you can only access visualforce page. Hence in your page u are using standard controller as well as save method and save method of standard controller redirect u to object's record page that is not visualforce page and you cant access that using site.

 

So wat you need to do, just override the save method. First u need to create extension class and in this class override the save method. Sample code is as given below:

 

Public class MyExtension

{

 Staff_Application__c staff;

public MyExtension(ApexPages.standardController con)

{

 staff=(Staff_Application__c)con.gerRecord();

}

 

public PageReference save()

{

if(staff!=null)

insert staff;

 

PageReference pr=new PageReference(PAGE_URL);

// if you want to redirect to any VF page then PAGE_URL will be = '/apex/pagename';

// and you want to redirect to any external site page the provide full qualified url

pr.setRedirect(true);

return pr;

}

}

 

And add this class as extension in your page:

 

<apex:page sidebar="false" showHeader="false" standardController="Staff_Application__c" extensions="MyExtension">

This was selected as the best answer
Art and Justice LeagueArt and Justice League

Alok_vibrant, you are amazing!  Thank you so much for your help!  It worked!

shephalishephali
Hello alok,
  I want to override save mathod of custom controller.as i have custom object 'mobille_agent__c' wid fields(Name,Last_Name__c,Device_Phone__c,Subscriber_ID__c)