Skip to main content The Trailblazer Community will be unavailable from 2/1/2025 to 2/2/2025. Please plan your activities accordingly.

Hi,

I'm trying to return values from a list in an apex class using the value from another list.

So I have list1 = [Select Contact__r.ContactEmail from Registrations__c Id in : lstRegistrations]

and what I want to do is check all the records from another object using the value of ContactEmail from above list.

So something like this:

list2=[Select Email from Site__c where Email contains (list1.Contact__r.ContactEmail)]

Can this be done?

Any help is much appreciated.

Thanks

1 answer
  1. Jan 19, 2017, 7:19 PM
    you need to create a list of Strings and then added all the emails of the first list, then you do the soql query, something like this:

    list1 = [Select Contact__r.ContactEmail from Registrations__c Id in : lstRegistrations]

    List<String> emails = new List<String>();

    if(list1.size()>0){

         for(Registrations__c r : list1){

              emails.add(r.Contact__r.ContactEmail);

         }

    }

    if(emails.size()>0){

          list2=[Select Email from Site__c where Email IN: emails]

    }

    else{

          //error message

    }
0/9000