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
RohanSharma8791RohanSharma8791 

I want to create a list of account and contact sObject . Whenever I click on the desired object it will show me all the related records for the sObject

I want to create a list of account and contact sObject . Whenever I click on the desired object it  will show me all the related records for the sObject

 
PriyaPriya (Salesforce Developers) 
Hi Rohan,

Firstly how do you want to acheive it? I mean via VF page or on Aura component ?

If you are looking via VF page then kindly use this sample code and modify it accordingly :- 

VF page :-
<apex:page controller="AccountController">
	<apex :form>
		<apex:commandButton value="AccountRecord" action="{!onClick}">
			<apex:pageblockTable value={!lstAccount} var="eachRecord">
				<apex:column value="eachRecord.Id">
				<apex:column value="eachRecord.Name">
			</apex:pageBlockTable>
	</apex :form>
</apex:page>
Controller :-
public Class AccountController{
public List<Account>lstAccount{get;set;}
	
	public AccountController(){
	lstAccount=new List<Account>();
	}

	public void onClick(){
	lstAccount=[SELECT id,Name FROM Account];
	}
}


Also you can refer this below links to get more ideas :- 
https://developer.salesforce.com/forums/?id=906F0000000BX9mIAG

Please mark it as best answer if this above answer helps you so that it can help others in future. 

Thanks and Regards,

Priya Ranjan
Salesforce Support

RohanSharma8791RohanSharma8791
Hey Priya,
Thanks for prompt reply .
Actually I want to create this in AURA component, and there needs to be a list of two sObject -"Account & Contact".
Whenever I click on Account object. It should show me account custom lookup.
and if I click on Contact object then it should show me contact custom lookup.