You need to sign in to do that
Don't have an account?
Hi Guys, How do I run this query outside a loop? any idea thanks
trigger duplicateContacsonAccount on Contact (before insert, before update) {
for (Contact newCon : Trigger.New) {
if (newCon.email != null)
{
List <Contact> exCon = [Select email from Contact where AccountId = :newCon.AccountId AND Email = :newCon.email Limit 1];
if (exCon.size() > 0)
{
newCon.addError('Duplicate Contact Found');
}
}
}
Here is the idea how to handle it. I wrote with notepad, It may have errors when compiled. However, this is just the ideas.
Hope this help.
Regards,
Le