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
Corey Edwards 11Corey Edwards 11 

Save and New Button keeps previous field values

Hi Guys,

I've created a Visualforce page which allows users to create quotes for customers. I want to create functionality which allows the user to adjust field values, click 'Save and New' and retain existing field values and create a new quote based on this. 

I can currently implement 'Save and new' functionality quite easily using:
 
public PageRedoSaveAndNew()
  {
    m_sc.save();
    
    PageReference pageRef = new PageReference(ApexPages.currentPage().getUrl());
    pageRef.setRedirect(true);
    return pageRef;
  }
I was hoping setting the Page Reference to the current page would help but it's not working. 

Any help would be greatly appreciated.

Cheers,

Corey
 
Raj VakatiRaj Vakati
Hi Corey , 

try this code

public PageRedoSaveAndNew() { m_sc.save(); PageReference pageRef = new PageReference(ApexPages.currentPage().getUrl()); pageRef.setRedirect(true); return pageRef; }
m_sc = new <StandardControllerObject>() ;

 
Corey Edwards 11Corey Edwards 11
Hi Rajamohan,

This code isn't working. It's giving me an error: Error: Compile Error: unexpected token: '=' at line 20 column 5

Here is my full code to review. Any help would be great :)
 
global with sharing class AuthCalloutExtension {

 ApexPages.standardController m_sc = null;
 public Quote quo { get; private set; }
 private String queryString;

  public AuthCalloutExtension (ApexPages.standardController sc)
  {
    m_sc = sc;
    quo = (Quote)sc.getRecord();
  }

public PageReference SaveAndNew() 
{ m_sc.save(); 
PageReference pageRef = new PageReference(ApexPages.currentPage().getUrl()); 
pageRef.setRedirect(true); 
return pageRef; 
}

m_sc = new <StandardControllerObject>() ;

}

This is with your alterations.

Cheers
Raj VakatiRaj Vakati
Hi Corey , 

Use this code ,

global with sharing class AuthCalloutExtension {
    
    ApexPages.standardController m_sc = null;
    public Quote quo { get; private set; }
    private String queryString;
    
    public AuthCalloutExtension (ApexPages.standardController sc)
    {
        m_sc = sc;
        if(sc.getRecord()!=null)
            quo = (Quote)sc.getRecord();
        else
        quo = new    Quote(); 
    }
    
    public PageReference SaveAndNew() 
    { m_sc.save(); 
     PageReference pageRef = new PageReference(ApexPages.currentPage().getUrl()); 
     pageRef.setRedirect(true); 
     quo =new Quote();
     return pageRef; 
    }
}
 
Corey Edwards 11Corey Edwards 11
Hi Rajamohan,

Thanks for your response. The quote is saved and the parameters are being passed to the URL but they arn't populating the fields. 

Do you know how to populate the fields using the URL parameters?

Cheers