You need to sign in to do that
Don't have an account?
Vikram Singh 157
Hi! My requirement is :- Avoid insertion of any lead if that record already exist as contact in my organisation.Match Email id of contact with lead], below trigger gives error
trigger leadrecords on lead(before insert){
list<string> leadEmails = new list<string>();
for(Lead lead:Trigger.new){
leadEmails.add(lead.Email);
}
List<Contact> leads = [SELECT Id, Email FROM Contact WHERE Email IN :leadEmails];
for (Lead newlead : leads){
if (newlead.email == leadEmails){
system.debug('Contsct is already exist');
}
else {
insert lead.Email;
}
}
list<string> leadEmails = new list<string>();
for(Lead lead:Trigger.new){
leadEmails.add(lead.Email);
}
List<Contact> leads = [SELECT Id, Email FROM Contact WHERE Email IN :leadEmails];
for (Lead newlead : leads){
if (newlead.email == leadEmails){
system.debug('Contsct is already exist');
}
else {
insert lead.Email;
}
}
If it solves the puzzle then please mark it as best answer and it will help others with similar issue!
All Answers
If it solves the puzzle then please mark it as best answer and it will help others with similar issue!
BTW, if you are new and willing to learn more about trigger, logics etc.. I would really recommend watching David Liu's videos on pluralSight.
Link = https://app.pluralsight.com/profile/author/david-liu
Hope this helps!