-3

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 ];
system.debug('leaddetails1'+SLAUSers);

  for(lead l : leaddetails){
    for(Customsettingobj__c us:USers){
        if(l.owner.email==us.Email__c){
            l.Flag_c__c=true;
        }
    }  
}
  • 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
0

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

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

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

for(lead l : leaddetails){
  if(EmailSet.contains(l.owner.email){
     l.Flag_c__c=true;
  }}

No need to use soql queries for custom settings

Read about custom settings:

https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_customsettings.htm

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.