+ Start a Discussion
LoneStar69LoneStar69 

Pulling a value comparing 2 lists

Basically, i am trying to compare 2 lists,
if a common value exists, i need to pull another value from that common value's record in a outgoing email.

public class Search {
    public static void Compare(){
Map<String, Case> ex1 = new Map<String, Case>();
Map<String, Imp__c> ex2 = new Map<String, Imp__c>();
List<Messaging.SingleEmailMessage> mails = new List<Messaging.SingleEmailMessage>();
String[] toAddresses = new String[] {'test@sample.com'};
    String s;
List<Case> lstCase = [SELECT Input__c FROM Case WHERE Origin = 'Web' and RecordType.DeveloperName = 'Imp'];
for(Case c : lstCase)
{
    ex1.put(c.Input__c, c);
}
List<Imp__c> mp = [SELECT actual__c FROM Imp__c WHERE actual__c != null];
for(Imp__c e : mp)
{
    ex2.put(e.actual__c, e);
}
        for(Imp__c em: mp){
        if(ex1.containsKey('em.actual__c')){
            s = em.Status__c;
            Messaging.SingleEmailMessage successmail = new Messaging.SingleEmailMessage();
    successmail.setToAddresses(toAddresses);
    successmail.setSenderDisplayName('Support');
              successmail.setSubject('Your Id is found:');
              successmail.setPlainTextBody('Your Id is with status'+s);
        mails.add(successmail);
              Messaging.sendEmail(mails);
        }        }    }    }

No errors, But doesn't seem to work.
Appreciate your time!!
surasura
one of the issues I see is you havent queried the Status__c field in your query 

List<Imp__c> mp = [SELECT actual__c FROM Imp__c WHERE actual__c != null];

but you are reffering it in the for loop

for(Imp__c em: mp){
        if(ex1.containsKey('em.actual__c')){
            s = em.Status__c;

try after fixing this
LoneStar69LoneStar69
Hi Sura,

shows no diff, not getting any emails.