I have a visualforce page which shows list of a custom object records in which id of another customobject id is passed in the url .One column shows the Account name which has lookup relationship with the custom object.I have one button mycommandbutton in each row and on click this will show the contact records for that account only in a different vf page.

I want to add one back link in my 2nd vf page so that it will go to the first vf page. My first vf page contains the customobject record id in the url and 2nd one account Id.i am not sure how to capture the customobject record id from the 2nd page so that it will navigate to first page again.

<apex:commandButton value="mycommandbutton" action="{!$Page.my2ndpage +'?id=' +obj.Account__r.Id}" immediate="true">
  • What is your first page url looks like? – highfive Jul 18 '14 at 16:36

You can pass the custom object Id as well into the second page via the query string like you are already doing it for the Account Id. Then use that in the second page controller to redirect the user to first page.

<apex:commandButton value="mycommandbutton" action="{!$Page.my2ndpage +'?id=' +obj.Account__r.Id+'&cust_id='+cust_obj_id}" />

In the second page controller use this custom object Id as below to redirect back into the first page (assuming getBack() is your method triggered to go back to the first page).

public PageReference getBack(){
  String accname = ApexPages.currentPage().getParameters().get('cust_id');
  PageReference firstPage = new PageReference('/apex/YourFirstPage?id='+accname);
  return firstPage;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.