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
anitha12anitha12 

Displaying Users along with related accounts and contacts

Hi All

 

How to display users, under perticular user I want to display related accounts & contacts (without commandlinks)

 

Example:

 

UserName:YYYYYYYY

 

Accountname   accountnumber  phone   etc(i.e account details)

 

Contact:  xxxxxxxx

 

 

Thanks &Regards

Anitha

Ritesh AswaneyRitesh Aswaney

By related Accounts, do you mean Owned by User ?

anitha12anitha12

Hi

 

yes Related accounts means, which user created records

Ritesh AswaneyRitesh Aswaney

UserId uId = UserInfo.getUserId();


for (Account  acc :  [Select Id, Name, (Select Id, Name from Contacts) where CreatedById = :uId)

{

 

System.debut('Account' + acc.Name);

 

for (Contact con : acc.Contacts)

System.debug (con.Name);

 

 

}

praveen murugesanpraveen murugesan
Hi Anitha,

You need to query all the fields whcih ever you need,

Eg
list<Account> acc = [SELECT Name, ( SELECT LastName  FROM Contacts WHERE CreatedBy.Alias = 'x') FROM Account WHERE CreatedBy.Alias = 'x'];

then put this in pageblock table and display it in a page.

Mark this as best answer if its helps.

Thanks.

Praveen Murugesan