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

From Opportunity Wizard - On Save send user to standard Add Products page

Very similar to the VF Cookbook Opportunity Wizard example, I have created an opportunity creation wizard because my users complain about too many clicks when creating an opportunity, adding products, etc.  My question is when the user clicks on Save, I would like to save the opportunity but instead of redirecting to the saved opportunity detail, go directly to the standard add products page.  I do not want to add the button to the VF page, just redirect to the standard add products search functionality.


I have been trying to set the addProductsURL as the page reference after saving the opportunity and have tried it a couple of ways in my controller without success.

public PageReference addProductsURL(){ PageReference p = new PageReference('/'+SelectSearch?addTo={!Opportunity.ID} ); p.getParameters().put('addTo',opportunity.Id); p.setRedirect(true); return p; This is how I tried to return the addProductsURL after saving opportunity: PageReference addProduct = Page.addProductsURL; addProduct.getParameters().put('id',this.controller.getId()); addProduct.setRedirect(true); return addProduct;


Thanks!  Any ideas are appreciated :)





Were you able to do this ?, please share if you have solution.


Thanks a ton in advance!





Yes, I was able to do this.

 public class newOpportunityController {

   // These following variables maintain the state of the wizard.  
   // When users enter data into the wizard, their input is stored  
   // in these variables.  
    Account account;
    Public string AccountID        {get; set;}
    Public Opportunity Opportunity    {get; set;}
     Public String addProductsURL    {get; set;}
   // The next four methods return one of each of the four class  
   // variables. If this is the first time the method is called,  
   // it creates an empty record for the variable.  
  public newOpportunityController(ApexPages.StandardController controller) {
    Account = (Account)controller.getRecord();
    Opportunity = new Opportunity();
    public String getAccountID() {
        return this.AccountID;
     public Account getAccount() {
        return [select id, name from Account 
                where id = :ApexPages.currentPage().getParameters().get('id')]; 

     public Opportunity getOpportunity() {
      if(opportunity == null) opportunity = new Opportunity();
      return opportunity;

   // The next three methods are used to control navigation through  
   // the wizard. Each returns a reference to one of the three pages  
   // in the wizard.  
   public PageReference step1() {
      return Page.OpptyStep1;
   public PageReference step2() {
      return Page.OpptyStep2;
  public PageReference addProduct() {
    PageReference pg = new PageReference('/ui/opportunity/SelectSearch?addTo=' );
    return pg;
   // This method performs the final save for all four objects, and  
   // then navigates the user to the detail page for the new  
   // opportunity.  
   public PageReference saveMe() {
      // Create the opportunity. Before inserting, create  
      // another relationship with the account.  
      Opportunity.accountId = Account.ID;
      insert Opportunity;
     return addProduct();
public PageReference cancel() {
  return RedirectToAccount();
private PageReference RedirectToAccount() {
  PageReference p = new  PageReference('/';
  return p;




Its working .....


Thanks a lot .