Skip to main content
8 answers
  1. Jun 17, 2021, 8:35 PM

    I was whacking my head on this!! Why you thought to give the class name "Contact"? Try the below code and please rename your class name.

    public class contactclass {

    public static void m(){

    list<account> clist=[select id,name, (select Name from contacts) from account];

    for(Account a: clist){

    for(Contact c : a.Contacts){

    System.debug('Account Name:: '+a.Name + ' ' + 'Contacts: ' + c.Name);

    }

    }

    }

    }