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
jucuzoglujucuzoglu 

How do I refresh the page after a record has been submitted

I have VP/Apex Class that updates a record.When the page first loads it grabs the first record that meets a particular criteria.

 

Here is the code that runs when the record is submitted. What should happen is upon submission it should update a checkbox (and some other fields) and then set the PageReference to the same page and then reload that page.

 

One of the criteria for the selected record is that the Resume Review Completed field should be false therefore after a submission the current record should drop out. (which it does if I reload manually)

 

 

public pageReference doSubmitReview()
	{
        
        if (ResumeStatus != '' && ResumeStatus != null)
        {
        	cRC.Status__c = ResumeStatus;	
        }
        cRC.Resume_Review_Completed__c = true;
        Update cRC;

        nextlink = '/apex/TBR_Resume_Review';
        PageReference nextPage = new PageReference(nextlink);
        return nextPage;
			
	}

What I notice is the bottom part (not url) seems to reload, it almost appears as if its reloading cache of the prior page load. If I manually choose to click reload I get the results I expect.

 

Is there something else I should be doing to force a proper reload.

 

 

Best Answer chosen by Admin (Salesforce Developers) 
Starz26Starz26

try adding:

 

nextPage.setRedirect(true);

All Answers

Starz26Starz26

try adding:

 

nextPage.setRedirect(true);

This was selected as the best answer
Srinu@dreamsSrinu@dreams
nextlink = '/apex/TBR_Resume_Review';
        PageReference nextPage = new PageReference(nextlink);
        return nextPage;

 Replace above code with:

PageReference nextpage = Page.MyPage;
nextpage.setRedirect(true);

return nextpage;
jd123jd123

hi jucuzogil

 

 

    

You need to set the redirect attribute on the pagereference to true:

 

PageReference nextPage = new PageReference(nextlink);
nextpage.setRedirect(true);

return nextPage;


OR
PageReference nextPage = new PageReference('/apex/TBR_Resume_Review');
nextpage.setRedirect(true);
return nextPage;


OR
PageReference nextPage =page.TBR_Resume_Review;
nextpage.setRedirect(true);
return nextPage;

This carries out a client side redirect and creates a new instance of the controller.  If you don't do this the existing controller instance will be re-used, along with any data you have entered.

 

if it is right solution for your question please mark it as resolved...

jucuzoglujucuzoglu

One other bit of information I neglected to mention for fear of complicating the solutions is that I am using the JQuery Mobile library.

 

If I don't set the redirect to true then I can see a spinner (Some sort of background AJAX call initiated by the VF Form POST) and the spinner disappears showing the same page. If I set the redirect to TRUE then the page displays undefined (which is probably erroring out client side).

 

Any idea why jQuery mobile might be showing undefined and perhaps how I could force the page to reload on the client side after the POST?

jucuzoglujucuzoglu

As a side note, I did resolve this issue by doing a client side reload. The apex:commandbutton has a oncomplete parameter that fires exactly when I want. Everything works like a charm.

 

Thanks to the contributors who provided the server side solution for properly redirecting the page.

 

 

 

hari.phari.p

To refresh the page use the bellow HTML content in the outputpanel. where ever you want to refresh the page

 

 <META http-equiv="refresh" content="1"/>

here you can set the content value to any number