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
JohnTaylorUKJohnTaylorUK 

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

bob_buzzardbob_buzzard

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

JohnTaylorUKJohnTaylorUK

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 :

 

"?com.salesforce.visualforce.ViewStateCSRF=ZZjwYm2KPwxiR6GUfnBLzNFRUxkp0PBCJqcCmAnfc4hpJCInoX9L6_s8iYNKSz8jgOy_3QVJHC249COOy9BcMGhQuV3sEXDGeXuX8HArBGmjzswUn.Y_IFDStkOK_xv5ttceU9xQLCKbWvaZwrfVxmEaCWw%3D&core.apexpages.devmode.url=1&ThePage%3Aj_id5=ThePage%3Aj_id5&ThePage%3Aj_id5%3APageBlock%3ACat=Question+%2F+Advice&ThePage%3Aj_id5%3APageBlock%3Achannel=Telephone&ThePage%3Aj_id5%3APageBlock%3ADetailedReason=_&ThePage%3Aj_id5%3APageBlock%3AFreeText1=&ThePage%3Aj_id5%3APageBlock%3AFreeText2=&ThePage%3Aj_id5%3APageBlock%3Aj_id31=Complete+%26+Save&ThePage%3Aj_id5%3APageBlock%3ALevel1=Store+Managers&ThePage%3Aj_id5%3APageBlock%3ALevel2=Other&ThePage%3Aj_id5%3APageBlock%3AMethod=Inbound&ThePage%3Aj_id5%3APageBlock%3Aoutcome=Arranged+call+back&ThePage%3Aj_id5%3APageBlock%3Astate=MS+Excel&ThePage%3Aj_id5%3APageBlock%3AtheField=00+%3A+00+%3A+00&ThePage%3Aj_id5%3APageBlock%3AType=Shots+Helpdesk&ThePage%3Aj_id5%3APageBlock%3AUserField=Russell"

 

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

 

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



 

Any ideas??

 

bob_buzzardbob_buzzard

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());
pageRef.setRedirect(true);
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.

JohnTaylorUKJohnTaylorUK

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());
pageRef.setRedirect(true);
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

bob_buzzardbob_buzzard

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;
                workHistoryWrapperList.clear();
                            
                isDone = true;
              }else
             {
                     
                isDone=false;
             }
           
               if(isDone) {
                    pageReference pg = new pageReference(ApexPages.currentPage().getURL());
                    pg.setRedirect(TRUE);
                    return pg;
             }
             else{
                 
                 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!
Rob_AlexanderRob_Alexander
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
                );
                
                billingLinesToUpsert.add(billingLineToUpdate);
            }
        }
        if (!billingLinesToUpsert.isEmpty()) {
            upsert billingLinesToUpsert;
        }
        
        //return to the billing record page
        PageReference pageRef = new PageReference('/'+billId);
        pageRef.setRedirect(true);
        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
hi
https://salesforce.stackexchange.com/questions/151973/how-to-refresh-visualforce-page-on-save-of-record

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

 
john wadejohn wade
Great Post thanks for sharing Walmartone Login (https://loginsx.com/walmartone/)