You need to sign in to do that
Don't have an account?
Pls help me on this Trigger
Hi,
This trigger is used to find the duplicates while entering the new contacts.
trigger dupcon on Contact (before insert, before update){
for (Contact c :trigger.new) {
//c.adderror('Hello');
if (c.FirstName != null && c.LastName!= null && c.BirthDate!= null) {
c.adderror('Hello');
List <Contact> dupcon = [SELECT Id FROM Contact WHERE FirstName = :c.FirstName AND LastName = :c.LastName ];
if (dupcon.size() >0 ) {
String Errmsg = 'ERROR';
Errmsg += 'Record Id'+dupcon[0].Id;
c.adderror(Errmsg);
}
}
}
}
Seems like the If condition doesnt work. I tried to add an errormessage just before the if statement. Then "hello" appears along with an Error msg saying "Contacts not associated with accounts are private and cannot be viewed by other users or included in reports."
Please help me on this . Thanks Much in Advance
This trigger is used to find the duplicates while entering the new contacts.
trigger dupcon on Contact (before insert, before update){
for (Contact c :trigger.new) {
//c.adderror('Hello');
if (c.FirstName != null && c.LastName!= null && c.BirthDate!= null) {
c.adderror('Hello');
List <Contact> dupcon = [SELECT Id FROM Contact WHERE FirstName = :c.FirstName AND LastName = :c.LastName ];
if (dupcon.size() >0 ) {
String Errmsg = 'ERROR';
Errmsg += 'Record Id'+dupcon[0].Id;
c.adderror(Errmsg);
}
}
}
}
Seems like the If condition doesnt work. I tried to add an errormessage just before the if statement. Then "hello" appears along with an Error msg saying "Contacts not associated with accounts are private and cannot be viewed by other users or included in reports."
Please help me on this . Thanks Much in Advance
There is it will hit the soql limit if you insert more than 100 records via data loader.
otherwise it will work if you remove the addError('hello')
Thanks
Karthick
All Answers
Here is the sample for your code:
http://www.sfdc99.com/2013/10/19/example-how-to-write-a-deduping-trigger-for-leads-and-contacts/
Thanks
Karthick
Hi Karthik,
I am referring the code from David Site only :). I just tried to implement the same .. But the If statement is not working. . Thats te reason, I just posted for the help.
Try below code
Please mark this post as solved so that it benifit others.
Thanks
Karthick
Thanks for the new code. But one Question. What's the problem with other code. Why that Contat Visibility error is happening
There is it will hit the soql limit if you insert more than 100 records via data loader.
otherwise it will work if you remove the addError('hello')
Thanks
Karthick