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
Swetha S415Swetha S415 

Get related Account, Contact, Opportunity and Quote Records using maps.

Hi All,
Could you please help me out how to achieve the below scenario using maps concept.
Scenario :
Having 4 object ===> Accounts, Contacts, opportunity and Quotes.
Accounts will have lookup to only Contact.
Contact will have lookup to only Opportunity.
Opportunity will have lookup to only Quote.

Create a visualforce page such that while on account search related contacts records should be displayed, if Contacts has opportunity records then those records to get displayed if it has none records nothing to get displayed. Similarly for opportunity has quote record those to be displayed.

Can anyone achieve this functionality by using Maps Concept? 
 
Best Answer chosen by Swetha S415
Khan AnasKhan Anas (Salesforce Developers) 
Hi Swetha,

I trust you are doing very well.

Please refer to the below blogs which has sample code which might help you with the above issue. Kindly try to implement according to your requirement.

http://forceschool.blogspot.com/2011/06/show-hierarchy-in-visualforce-page.html

http://www.forcetree.com/2011/04/tree-view-in-visualforce-page.html

http://salesforceblogger.blogspot.com/2012/03/hierarchy-in-visualforce.html


I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in future.

Thanks and Regards,
Khan Anas

All Answers

Khan AnasKhan Anas (Salesforce Developers) 
Hi Swetha,

I trust you are doing very well.

Please refer to the below blogs which has sample code which might help you with the above issue. Kindly try to implement according to your requirement.

http://forceschool.blogspot.com/2011/06/show-hierarchy-in-visualforce-page.html

http://www.forcetree.com/2011/04/tree-view-in-visualforce-page.html

http://salesforceblogger.blogspot.com/2012/03/hierarchy-in-visualforce.html


I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in future.

Thanks and Regards,
Khan Anas
This was selected as the best answer
Bhargavi TunuguntlaBhargavi Tunuguntla
Hi Swetha 


You can the related Account records as below:
 
Account acc=[select id,name from Account where name=:Accountname limit 1];

Map<Id,contact> contactMap=new Map<Id,contact>([select id,name,AccountId from contact where AccountId=:acc.id]);

Map<Id,opportunity> oppMap=new Map<Id,opportunity>([select id,name,Contact_Name__c from opportunity where Contact_Name__c in: contactMap.values()]);

Map<Id,Quote> QuoteMap=new Map<Id,Quote>([select id,name from Quote where OpportunityId in: oppMap.values()]);

Hope this will be helpful. Please try the code and let me know if any issues.

Thanks
Bhargavi.