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
Vijaya Kumar RegantiVijaya Kumar Reganti 

pass the Id to the VF page's URL from class and to get the Id from the VF page's URL into the class

How do I pass the record Id to the URL of the VF page from the class??

 

How can I get the record Id from the URL of the VF page into the class??

 

Best Answer chosen by Admin (Salesforce Developers) 
Sunny670Sunny670
1. to get the record id of the page in apex class
Id=apexpages().currentpage().getparameters().get('id');
2. on click of the button you can use the below code to pass the id to url.


PageReference requestPage = new pagereference('/apex/pagename?id='+id);
return requestpage;

All Answers

Sunny670Sunny670
1. to get the record id of the page in apex class
Id=apexpages().currentpage().getparameters().get('id');
2. on click of the button you can use the below code to pass the id to url.


PageReference requestPage = new pagereference('/apex/pagename?id='+id);
return requestpage;
This was selected as the best answer
sushant sussushant sus
if you want to pass id in url you have to use apex: param
example :
<apex:param name="q" value="{!contact.name}"/>
then use
apexpages().currentpage().getparameters().get('q');