+ Start a Discussion
kenzokenzo 

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.  :)

Message Edited by kenzo on 10-30-2009 12:23 PM
Message Edited by kenzo on 10-30-2009 12:25 PM
Best Answer chosen by Admin (Salesforce Developers) 
prageethprageeth

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

Anand@SAASAnand@SAAS

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. 

  

prageethprageeth

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> 

 

 

This was selected as the best answer
tunedogtunedog

Can anyone give me some clues on how to write a unit test for this extension?

Thanks in advance.