Hi Giddamreddi, What exactly you want ,where you want inside your class or soem where else ?
Assume that you have instance of account as acc ,If you want all contacts related to that account you can achieve as below List<Contact> conList=acc.Contacts ;
Please try to execute below code in develper console. In this case with parent record you will get child contact records as well :-
List<Account> listAccount = [select id,name , (select id,firstName , LastName from contacts ) from account limit 10];
For(Account acc : listAccount )
{
List<Contact> lstContact = acc.contacts;
for(Contact cont : lstContact )
{
System.debug('Name is----'+cont.FirstName);
}
}
NOTE: This code has not been tested and may contain typographical or logical errors
Please mark this as solution by selecting it as best answer if this solves your problem, So that if anyone has this issue this post can help
Thanks
Amit Chaudhary
All Answers
What exactly you want ,where you want inside your class or soem where else ?
Assume that you have instance of account as acc ,If you want all contacts related to that account you can achieve as below
List<Contact> conList=acc.Contacts ;
Let me incase any doubt .
Please try to execute below code in develper console. In this case with parent record you will get child contact records as well :-
List<Account> listAccount = [select id,name , (select id,firstName , LastName from contacts ) from account limit 10];
For(Account acc : listAccount )
{
List<Contact> lstContact = acc.contacts;
for(Contact cont : lstContact )
{
System.debug('Name is----'+cont.FirstName);
}
}
NOTE: This code has not been tested and may contain typographical or logical errors
Please mark this as solution by selecting it as best answer if this solves your problem, So that if anyone has this issue this post can help
Thanks
Amit Chaudhary