1

I have two custom objects contact and property. I would like to embedd a visual force page in the contact custom object which would do the following.

1) Access a field in the contact object and fetch the records from the property object related to the field in the contact object (say a email or a unique number.)

My question is how do i access the contact object field in the visual force page?

1 Answer 1

1

Create a normal VF page with standard controller as your 'Contact' object. Then in the controller of the page, assume that you are being passed a parameter named "id" to the page.

ID ContactID = ApexPages.currentPage().getParameters().get('id')

So this will get you the ID of the contact record that is being open. Once you have this then you can query out the "contact" record

Contact__c conRec = [SELECT id, Selected_Field__c FROM Contact__c WHERE id = :ContactID ];

So now you have the required field. You can now write your custom logic to obtain the property records. Hope this helps.

6
  • My Url look something like this. salesforce.com/a0Bm0000004m1ZAEAY This is the URL for the detail of the custom object. When i use the ApexPages.currentPage().getParameters().get('id') it doesn't get the details i want. I used the same method you mentioned. Any advice?
    – Karthick
    Commented May 4, 2016 at 5:07
  • This will work only when you put your inline VF page in to the page layout. Or to manually simulate this trying passing an explicit ID like - ../apex/MyPage?id=a0Bm0000004m1ZAEAY
    – Prajith
    Commented May 4, 2016 at 6:29
  • I am using an inline page. But when i try to get the id from the URL it doesn't work.
    – Karthick
    Commented May 4, 2016 at 10:24
  • Try system.debug on the retrieved ID, try it out for explicit ID passing first and then the inline. It should work. Good luck :)
    – Prajith
    Commented May 4, 2016 at 11:56
  • This is way using getting the record directly. In this example the inline VF page is on account - you could easily change it to contacts - blog.jeffdouglas.com/2009/05/08/…
    – Prajith
    Commented May 4, 2016 at 11:59

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .