You need to sign in to do that
Don't have an account?
Redirect URL on "Save" (standardController - Custom Object)
SuperNewbie trying to achieve simple task. I have a VF page for Public Access (customers to fill out warranty info) with a standardController referencing a Custom Object (the warranty info fields).
After entering data and clicking: commandButton action="{!save}" I want to redirect user to outside URL (e.g. HTML "thank you" page).
Should I be adding an Extension ( e.g. standardController="Warranty__c" extensions="redirect" ) and if so, I'd love a sample of the correct Apex Class code.
The closest I've gotten is to have the page redirect upon loading. A bit premature I'm afraid.
Thanks in advance to anyone willing to help a non-developer develop. :)
Hello Kenzo;
Your controller sould be like below. I assume that you need to redirect to a VF page named myThankyouPage.
Controller:
public class myClass{
ApexPages.StandardController controller;
public myClass(ApexPages.StandardController con){
controller = con;
}
public PageReference save() {
controller.save();
return page.myThankyouPage;
}
}
In your first Page(not thankyou page):
<apex:page standardController="Warranty__c" extensions="myClass">
<apex:form>
<apex:commandButton value="Save Data" action="{!save}"/>
</apex:form>
</apex:page>
All Answers
An extension is the cleanest way to implement this. Create an extension and have a method call redirectToThankYou(), in that method, calll the standardController's "Save" and then redirect to the page you need to go.
Hello Kenzo;
Your controller sould be like below. I assume that you need to redirect to a VF page named myThankyouPage.
Controller:
public class myClass{
ApexPages.StandardController controller;
public myClass(ApexPages.StandardController con){
controller = con;
}
public PageReference save() {
controller.save();
return page.myThankyouPage;
}
}
In your first Page(not thankyou page):
<apex:page standardController="Warranty__c" extensions="myClass">
<apex:form>
<apex:commandButton value="Save Data" action="{!save}"/>
</apex:form>
</apex:page>
Can anyone give me some clues on how to write a unit test for this extension?
Thanks in advance.