I have created a VF page which is form to save account information. This page is visible to public and user with no logins can access it. I use this internally in my organization but I have plans to build login page to let only authorized person access it,but for now I have just this:
I use the Account standard controller in my VF page:
<apex:page standardController="Account" sidebar="false" showHeader="false">
<apex:form >
<apex:pageBlock title="Edit Account">
<apex:pageMessages/>
<apex:pageBlockSection columns="1">
<apex:inputField value="{! Account.Name }"/>
<apex:inputField value="{! Account.Phone }"/>
<apex:inputField value="{! Account.Industry }"/>
<apex:inputField value="{! Account.AnnualRevenue }"/>
</apex:pageBlockSection>
<apex:pageBlockButtons >
<apex:commandButton action="{! save }" value="Save" />
</apex:pageBlockButtons>
</apex:pageBlock>
</apex:form>
</apex:page>
When a user enters the details and click save. I get an authorization error Required page. When I use the page in Salesforce I am redirected to Account page once I click save. I assume that public users would not have access to this account page. How can I redirect this page to some other visual force page which says "Saved Successfully". Basically how to redirect a VF page to another VF page.
Answer:
I figured it out myself by reading the Salesforce's awesome documentation. I had to write a controller class(extensions) like below to redirect my page:
public class RedirectionClass{
private final Account acct;
// The extension constructor initializes the private member
// variable acct by using the getRecord method from the standard
// controller.
public RedirectionClass(ApexPages.StandardController stdController) {
this.acct = (Account)stdController.getRecord();
}
public PageReference save() {
insert acct;
PageReference acctPage= new PageReference('http://hometest1-developer-edition.na34.force.com/test/helloworld');
acctPage.setRedirect(true);
return acctPage;
}
}