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
Anas AlamourAnas Alamour 

Retrieving parent records based on child conditions

I have contact as a parent object and program (custom object ) as child object , the relationship is lookup. I have a requirment to generate report for the contacts that have specific programs , for example , only i need to retrive the conatcs records that have programs with name "A" and "B".  How i can do that using Reports , SOQL query or Aoex code.
Malika Pathak 9Malika Pathak 9

Hi Anas,

List<Account> accList=new List<Account>();
accList=[SELECT Id,(SELECT Id,LastName,Email from Contacts where LastName Like '%a%' OR LastName Like '%b%') from Account LIMIT 1];
for(Account acc:accList){
    for(Contact con:acc.contacts){
        system.debug('lastname==>'+con.LastName);
    }
}
system.debug('accList==>'+accList);

If you find this helpful mark it as the best answer.