You need to sign in to do that
Don't have an account?
Shubham Sengar
trigger problem 5
write a trigger will prevent user from creating a lead that already existing as a contact .?
hint:: we will use leads/contacts email address to detact duplicates
hint:: we will use leads/contacts email address to detact duplicates
{
for (Lead myLead : Trigger.new)
{
if (myLead.Email != null)
{
List<Contact> dupes = [SELECT Id FROM Contact WHERE Email = :myLead.Email];
if(dupes.size()>0)
{
trigger.new[0].id.addError('lead already Exist as a contact ');
}
}
}
}
All Answers
Try on your own, if you are really stuck with any error message or any problem, please share it here we are here to help you.
trigger FindDupes on Lead (before insert, before update) { for (Lead myLead : Trigger.new) {
if (myLead.Email != null) {
List<Contact> dupes = [SELECT Id FROM Contact WHERE Email = :myLead.Email];
if (dupes.size() > 0) {
myLead.Dupe_Contact__c = dupes[0].Id;
} else {
myLead.Dupe_Contact__c = null;
} }
} }
but its gives error
[Error] Error: Compile Error: Invalid field Dupe_Contact__c for SObject Lead at line 7 column 9
{
for (Lead myLead : Trigger.new)
{
if (myLead.Email != null)
{
List<Contact> dupes = [SELECT Id FROM Contact WHERE Email = :myLead.Email];
if(dupes.size()>0)
{
trigger.new[0].id.addError('lead already Exist as a contact ');
}
}
}
}