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
JJamesJJames 

onClick refresh current URL with commandButton

I am having issues refreshing a page when I click save on my visualforce page.  I want to keep the current url but when I try and pass the url from the controller it loses the reference to the timecard id in the url:
 
public PageReference save(){
PageReference pageRef = new PageReference(ApexPages.currentPage().getUrl());
system.debug(pageRef);
pageRef.setRedirect(true);
return pageRef
}
and the logs show: 09:18:52:328 CODE_UNIT_FINISHED VF: /apex/TestAccountPage but the link I am using is /apex/TestAccountPage?timecardId={!timecard.id}
I have also tried to implement it in the visual force page which would be my preference using the onclick in the commandbutton:
onclick="window.location= ' /apex/TestAccountPage?timecardId={!timecard.id} ' "

but it also just goes to the /apex/testaccountpage when i click the button.  Any help?
 
Best Answer chosen by JJames
srlawr uksrlawr uk
I think if you want to use Apex (the first way) you need to add the parameter to the pagreference using the method:
 
pageRef.getParameters().put([name],[value]);

as you can see here.. https://developer.salesforce.com/forums/?id=906F000000093H7IAI

All Answers

srlawr uksrlawr uk
I think if you want to use Apex (the first way) you need to add the parameter to the pagreference using the method:
 
pageRef.getParameters().put([name],[value]);

as you can see here.. https://developer.salesforce.com/forums/?id=906F000000093H7IAI
This was selected as the best answer
JJamesJJames
Thanks! got it to work with the following apex:
 
public PageReference save() {
		UPDATE entryList;
        
        // Send the user back to current page.  
		PageReference pageRef = new PageReference('/apex/TestAccountPage');
        pageRef.getParameters().put('timecardId',timecardId);
        system.debug(pageRef);
		pageRef.setRedirect(true);
		return pageRef;

	}