How to compare list custom setting records with other list of lead?

//this list store the list of lead records
List<Lead> leaddetails=new List<Lead> leaddetails();

//This custom setting store the list user emails and names
List<Customsettingobj> USers= [Select Name,Email__c from Customsettingobj__c ];

How to compare whether lead owner email is in custom setting records or not?

I have tried multiple ways but not able to achieve

I have tried with the below Approch , somehow it is not working in all scenorios

List<Lead> leaddetails

List<Customsettingobj__c> USers= [Select Name,Email__c from Customsettingobj__c ];

  for(lead l : leaddetails){
    for(Customsettingobj__c us:USers){
  • Please include code what have you done so far. – Reshma Nov 7 '18 at 6:10
  • updated the code which i have tried, check once – Prince Nov 7 '18 at 6:15

Get your custom setting data, add that data to Emailset.

Set<String> EmailSet = new Set<String>();  
for (Customsettingobj__c rv : Customsettingobj__c.getAll().values()) {

check that EmailSet contains lead owner email.If yes make flag is true

for(lead l : leaddetails){

No need to use soql queries for custom settings

Read about custom settings:


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.