+ Start a Discussion

VF page save and then reload current page

Hi All,


I hope this is a simple problem and I'm just missing something.


I am trying to build a controller extension that saves a VF form page details and then reloads the same page.


This should be straight forward but when I try and use the documented way to do this, the data is saved and the return page is the page I wanted, but along with it the URL of the page , a long string of test has been appended to the end, the apex seems to be wanting to map the details of the fields on the page when it reloads.


This in itself would not a problem, but some users are getting an authentication error when the page reloads, and i assume this has something to do with it.


Any help would be great.


Thanks all


How are you reloading the page? Are you simply returning the current page or are you constructing your own page reference?


The page in question is a a basic form that I would like to save , clear the drop downs and let the user complete again (over and over) as it will be used for logging activity.


at the moment , the data is saved and the page is reload , but a long string is added to the end of the URL, like this :




unsure why its happening. below is the section of the controller that should do the work:


      PageReference pageRef = ApexPages.currentPage();
      return pageRef;


Any ideas??



Wow - its trying to maintain the viewstate through a URL parameter.  Nice.


Looks like you need to recreate the pagereference rather than using a reference to the existing one.


The following should do it:


PageReference pageRef = new PageReference(ApexPages.currentPage().getUrl());
return pageRef;

Does your VF page use a standard controller?  If so, you'll need to add the record id as a parameter to the page reference.


Thanks Bob,


Below is my full controller , with the chages you suggested, could you let me know if this is what you had in mind ?


public class Logger_Extend {

    private final RCA_Logger__c Log;

    public Logger_Extend (ApexPages.StandardController
                                stdController) {
       Log = (RCA_Logger__c)stdController.getRecord();

     public PageReference XX() {
 // Add the account to the database.   
    insert Log;
// Send the user back to current page.  
PageReference pageRef = new PageReference(ApexPages.currentPage().getUrl());
return pageRef;


 I am using a standard controller and this is just an extension, do I still need to get the record ID and if so how ?


Thank again


As you are only inserting new objects, you should be good to go as you are.

Kt YadavKt Yadav
Hi Bob,
I am facing the same issue as it is appedning the value in the URL.
public pageReference saveRec(){
 if(recCount < 6 ){
                 work.Employer__c = workHistory.Employer__c;
                work.Ending_Job_title__c = workHistory.Ending_Job_title__c;
                insert work;
                isDone = true;
               if(isDone) {
                    pageReference pg = new pageReference(ApexPages.currentPage().getURL());
                    return pg;
                 return null;
John Crusan 6John Crusan 6
I went through 50 posts and you're the only one that's got this right Bob, Thanks!
what if I am updating existing records, as such?: 
if (billableShift.Billing_Line_ID__c != null) {
                AcctSeed__Billing_Line__c billingLineToUpdate= new AcctSeed__Billing_Line__c (
                    Id = billableShift.Billing_Line_ID__c,
                    AcctSeed__Billing__c = billId,
                    Shift__c = billableShift.Id,
                    AcctSeed__Date__c = billableShift.sirenum__Shift_Date__c,
                    Health_Professional__c = billableShift.sirenum__Contact__c,
                    AcctSeed__Hours_Units__c = billableShift.Actual_Length__c,
                    AcctSeed__Rate__c = billableShift.Bill_Rate__c,
                    AcctSeed__Comment__c = billableShift.Comments_formatted__c
        if (!billingLinesToUpsert.isEmpty()) {
            upsert billingLinesToUpsert;
        //return to the billing record page
        PageReference pageRef = new PageReference('/'+billId);
        return pageRef;

how do I get the Billing page (or at least the Billing Lines related list) to reload automatically?
cmadar 42cmadar 42
pandu ranga 8pandu ranga 8

<apex:commandButton action="{!SaveAndNew}" value="Save and New"/>
aliaa12 joealiaa12 joe
Great Post! Thank you for visiting here. Hyperfund login (https://tractorsinfo.com/hyperfund-login/)
Shivam SolankiShivam Solanki
Thanks for sharing this informative blog with us. Are you looking for ways to improve your writing skills?
Pickon is a Buzz Feed, Entertainment, Magazine Website, Pickon is the best website to find and share content on internet that offers content writing, entertainment news, quizzes, facts, travel blogs and viral post services to its users.
Blog: Vegamovies (https://pickon.in/vegamovies/" target="_blank)
Blog: Katmoviehd (https://pickon.in/katmoviehd/" target="_blank)