trigger Attachtolead on Case (before insert) {
list<lead> l =new list<lead>();
list<case> clist =new list<case>();
set<string> emailtext=new set<string>();
list<case> cli=new list<case>();
set<string> lid=new set<string>();
for (case c : Trigger.new) {
if(c.ContactID == null && c.Origin=='web')
emailtext.add(c.SuppliedEmail);
cli.add(c);
}
l=[select id,email,phone,country,fax from lead where email IN: emailtext];
for(lead l1: l){
lid.add(l1.id);
}
if(lid.size()>0){
lead l2=[select id,email,phone,country,fax from lead where id IN:lid Limit 1];
for (case c : cli) {
c.Lead__c=l2.id;
}
}
}
I want to connect case to lead checking with supplied email .but it is not working .can some one can help me regarding this ?