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
noob123noob123 

Pass Contact ID to a VF Page

I have a button on a Contact details page that launches a Visualforce page.  This Visualforce page uses a custom controller for various reasons, but I need to reference the specific Contact that the user launched from.  Is there an easy way to pass the Contact ID as a parameter to the new Visualforce page and reference it throughout my code?

 

Thanks..

Best Answer chosen by Admin (Salesforce Developers) 
VisualForceVisualForce

Hi..

  Try this  

button behavior : onclick javascript

javascript code:

 window.location.href = '/apex/urVFpagename?id={!Contact.Id}';

 

In ur controller class:

 

u can fetch this id

id contid=Apexpages.currentPage().getParameters().get('id');

All Answers

JimRaeJimRae
The easiest way to do this is to base your page on the standard controller, and then use your custom controller as an extension. Look at the documentation on controller extensions for the format, but it is only a few lines of code, and you will get the power of both.
VisualForceVisualForce

Hi..

  Try this  

button behavior : onclick javascript

javascript code:

 window.location.href = '/apex/urVFpagename?id={!Contact.Id}';

 

In ur controller class:

 

u can fetch this id

id contid=Apexpages.currentPage().getParameters().get('id');

This was selected as the best answer
Jack D PondJack D Pond
Ok, this is not the prettiest, but it does work if you are trying to pass the contact information to Case in a custom controller.
c = (Case)stdController.getRecord();
c.ContactId = ApexPages.currentPage().getParameters().get('def_contact_id');
Contact thiscontact = [Select Id, Name, Phone, MobilePhone, Email, Fax from Contact
            where Id = :c.ContactId ];
c.Contact = thiscontact;
In this case you would need to add to the query list all the fields you later intend to use.