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

how to pass the ID one page to other ,when i click a button? (Account and contact)

There are two visualforce page one is Account and another one is contact. 


In Account page, create a Account and related list contact. when i click a contact button in Account page, Account id is passed in the contact page.


for eg:








Accid(foreign key)


Ankit AroraAnkit Arora

I don't know if my understanding matches yours, but I think you have a visualforce page "Account" where you fill all fields of account and displays a section where you can create contact. Now you want to get accountid to create contact.


For this when you are clicking on button to create contact you first need to create account and then use its id in contact page. Hope this will help.



Ankit Arora





Accountid passed in the contact page. plz send controllerclass and vfpage of contact.




Account                          contact


Accname                       contactid

Address                         accountid(foreign key Account)


I m waiting fr ur reply

Shashikant SharmaShashikant Sharma

Pass it in query parameter


when you open new url for contact page just add this to your url


YourURl?accountid=id_that_you_want_to_passch it 


on contact page controller fet using in constructor






 From my understanding what  he is asking is ,Two actions should be done at the same time in one button click.


                               1. Saving account  record .


                               2. Get  id of account  and pass to another Vfpage.


I am satisfield with u r answer in case of 2nd action, we can pass id in query string parameter and we can get that id using apexpages() methods.But i want to know how we can get id of newly created account in controller.Can u please suggest in this case.


Thank u


SFDC Blue Fish





Shashikant SharmaShashikant Sharma

HI SfdcBlueFish,


Geeting id is not difficult on a apex conrooler , as sson as you save any record


Accoaunt ac = new Account(Name='My Account');

insert acc;


Id accID =;


you can get id like this and pass it in query string parameter


I hope, I understood your question right.



Ramesh SomalagariRamesh Somalagari
Can u share the code I have also same proble

Best regards,