+ Start a Discussion

How to dynamically set the PageReference based on the previous page

I have a custom object to hold site records (site__c).  In the process of working through a collection of Visual Force pages I want to provide the option for a user to quickly add a site and then continue with the process they are currently on.



1) User creates a new opportunity (id=000000001)

2) User clicks "Add Product Wizard" which launches /apex/AddProdWiz?id=000000001

3) User is prompted to select a site from the list of existing sites (associated at an account level)

4) If the site isn't listed the user should click "Add a site"


Here is where I need help.  I want the user to complete the same form displayed when the user accesses the site__c object and clicks "new".  I also want them to be returned to /apex/AddProdWiz?id=000000001 when he/she is done adding the site.  Ideally, I would like the user to be returned to /apex/AddProdWiz?id=000000001&siteID=000000002 so I can automatically select the newly added site.


Should I be sending the user to a Visual Force page that uses a standardController="site__c"?  If so, how do I tell it to display the add form on the screen?


Thank you for your help.


Im not sure about whether this works in your case....but it worked for me when i tried doing it for an custom EDIT button





you will need to override the NEW button and call a method in your apex class. the method will be of type pagerefernce...and you will need to give the above url.


That worked for the example I provided.  When I  added the additional querystring parameters the functionality didn't work as well.  It appears SalesForce.com didn't know if my additional querystring parameters were supposed to be interpreted by the site screen or appended to the retURL parameter.


Either way, I've realized the additional flags I need to set when an edit is completed will be easier to manage on a Visual Force page.  I've been told it is easy to embed the edit portion of an object on a Visual Force page, but I can't find any reference of how to do it.


Any help is greatly appreciated.