You need to sign in to do that
Don't have an account?
Hi Guys, I'm trying to create SOQL to list all Contact Records with the same Account Id..any idea? thanks!
Hi Guys, I'm trying to create SOQL to list all Contact Records with the same Account Id..any idea? thanks!
https://developer.salesforce.com/forums?id=906F00000008j1lIAA
You can write following soql and iterate over it.
or
Thanks,
Himanshu
Salesforce Certified Developer | Administrator | Service Cloud Consultant
P.S. If my answer helps you to solve your problem please mark it as best answer. It will help other to find best answer.
@Himanshu , Thanks for the suggestion, that is exactly what I need. I just need to know how will I create the bind variable :account.id ?
trigger dt on Contact (before insert, before update) {
for (Contact newCon : Trigger.New) {
if (newCon.AccountId != null)
{
List <Contact> exCon = [Select Id from Contact where AccountId = :newCon.AccountId Limit 200];
if(newCon.Email == exCon[0].Email )
{
newCon.addError('Duplicate Contact Found');
}
}
}
}
it only matches the first one on the list
this should fix it..
trigger dt 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');
}
}
}
}
Thanks,
Himanshu