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
DevWannabeDevWannabe 

Custom List/Report in VF page to display on record detail

I have built a custom object that attaches two accounts together, similar to the Parent Account function, but allows to add details about the relationship.  I set it up as a M-D to Accounts, so there is a Master (Parent) Account on this record and a lookup (Child) to another Account on this record along with other fields that detail the type of relationship between the two Accounts.  What I would like to do is show all the Contacts on the "Child" Accounts that are related to the "Parent" Account on that Accounts detail page.  My thought was to create a VF page and put it in a section on the Account detail page that shows this list/report, but I am having trouble figuring out how to get the necessary data in there.  I would like it in the following format if possible...

 

Relationship Type       Account Name

    Contact name        Contact Phone    Contact Email

 

Buyer      ACME

  John Smith     111-222-3333    johnsmith@acme.com

  Jane Smith     111-222-4444    janesmith@acme.com

Seller     RoadRunner Inc.

  Blue Bird        333-333-4444    bluebird@rrinc.com

  Fast Bird        333-333-9999    fastbid@rrinc.com

 

 

So, effectively you are interating over the custom object on an Account to list all those records and some details from those records and then iterate over the contacts from the accounts on each of those records.  Any guidance would be greatly appreciated...

WizradWizrad

So to have this within a standard detail page:

 

1) Apex needs to get the id of the current record from the URL.

2) Use the id as part of a where clause in a SOQL query.  Select from your custom junction object where the parent has the id you took from the url.  This same soql query can get the necessary child data.

3) Another soql query to query for all contacts underneath the child account.

4) visualforce to display it all.

5) Embed this visualforce page in the standard detail page.