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
SimrinSimrin 

Refresh Page after save is executed

public with sharing class controller1{
public PageReference save() {
                /Manipulation
                return null;
    }
}
I get values form page and save data in database.
After the control is back to the page, old values are displayed.

When i refresh the Page Manaully, i get the updated values.
How can i refresh the page from controller, so that i should avoid manual refresh
Best Answer chosen by Simrin
Himanshu ParasharHimanshu Parashar
can you try following code. replace YOURPAGNAME with your apex page name and replace RECORD with your object name.
public with sharing class controller1
{ 
    public PageReference save() {   
    //Manipulation 
    insert RECORD;
    PageReference pageRef = new PageReference('/apex/YOURPAGNAME?id=' + RECORD.ID); 
    pageRef.setRedirect(true); 
    ​return pageRef;
    } 
}

and let us know one thing, are you using <apex:actionfunction> while calling your function?

Thanks,
Himanshu


 

All Answers

CLKCLK
It should refresh the page automatically if you dont have ajax on button/link/actionfunction.

From where you calling this method?
Himanshu ParasharHimanshu Parashar
you can try following code.
 
PageReference pageRef = new PageReference(ApexPages.currentPage().getUrl());
pageRef.setRedirect(true);
​return pageRef;

Thanks,
Himanshu
Salesforce Certified Developer | Administrator | Service Cloud Consultant

P.S.  If my answer helps you to solve your problem please mark it as best answer. It will help other to find best answer.

 
SimrinSimrin
Hi Himanshu,

When i use below code ,
 

public with sharing class controller1
{ 
    public PageReference save() {   
    /Manipulation 
    PageReference pageRef = new PageReference(ApexPages.currentPage().getUrl()); 
    pageRef.setRedirect(true); 
    ​return pageRef;
    } 
}


It get blank page with no errror displayed
Himanshu ParasharHimanshu Parashar
can you try following code. replace YOURPAGNAME with your apex page name and replace RECORD with your object name.
public with sharing class controller1
{ 
    public PageReference save() {   
    //Manipulation 
    insert RECORD;
    PageReference pageRef = new PageReference('/apex/YOURPAGNAME?id=' + RECORD.ID); 
    pageRef.setRedirect(true); 
    ​return pageRef;
    } 
}

and let us know one thing, are you using <apex:actionfunction> while calling your function?

Thanks,
Himanshu


 
This was selected as the best answer
SimrinSimrin
Hi Himanshu,

My page had actionFunction, but your solution worked for me.
Thank you very much.