In contact object i enter the last name field is kiran and Email is kiran123@gmail.com , and next time i enter the same name and email so this type of combinations not repeated? How can i write a validation rule or Workflow?
You cannot achieve this using workflow or validation rule. You have to write a trigger on contact object and there you can add whatever logic you want.
Hi pankaj, my question is Once i enter the last name and Email (last name=raju ,email=raju123@gmail.com) next time i enter the same values it will show error (Not repeated the same time of combinations, Suppose last name is raju Email is different ,Email is Raju123@gmail.com Last name is different)? how to write validation rule or Workflow?
*Hi pankaj,my question is Once i enter the last name and Email (last
name=raju ,email=raju123@gmail.com ) next time i enter
the same values it will show error (Not repeated the same time of
combinations, Suppose last name is raju Email is different ,Email is
Raju123@gmail.com Last name is different)? how to
write validation rule or Workflow?*
For this purpose you need to fetch the existing records that is the reason you cannot do it in validation rule. If you donot want duplicate records based on one field you can make that field unique at field level. Hope this makes sense.
Let us know if you have any question. Your trigger logic should be on before insert logic and you need to fetch all the records whose name amd email matches your criteria.
Don't forget to select best answer to make our efforts visible in the developer forum. Please mark this as solution by selecting it as best answer if this solves your problem, So that if anyone has this issue this post can help
Don't forget to select best answer to make our efforts visible in the developer forum. Please mark this as solution by selecting it as best answer if this solves your problem, So that if anyone has this issue this post can help
Simply create a custom field called unique check or any name you prefer of type text and mark that field as unique (tick unique check box) . then define and workflow rule with filed update action to populate unique check field with value lastname + ' '+Email. done
List<Contact> lstContact = [Select Id, LastName, Email from Contact];
for(Contact con : trigger.New){
for(Contact c : lstContact){
if(con.LastName == c.LastName && con.Email == c.Email)
con.Email.addError('Duplicate Found');
}
}
}
All Answers
can you plz Write a trigger?
my question is Once i enter the last name and Email (last name=raju ,email=raju123@gmail.com) next time i enter the same values it will show error (Not repeated the same time of combinations, Suppose last name is raju Email is different ,Email is Raju123@gmail.com Last name is different)? how to write validation rule or Workflow?
For this purpose you need to fetch the existing records that is the reason you cannot do it in validation rule.
If you donot want duplicate records based on one field you can make that field unique at field level.
Hope this makes sense.
Let us know if you have any question.
Your trigger logic should be on before insert logic and you need to fetch all the records whose name amd email matches your criteria.
Don't forget to select best answer to make our efforts visible in the developer forum.
Please mark this as solution by selecting it as best answer if this solves your problem, So that if anyone has this issue this post can help
List<Contact> lstContact = [Select Id, LastName, Email from Contact];
for(Contact con : trigger.New){
for(Contact c : lstContact){
if(con.LastName == c.LastName && con.Email == c.Email)
con.Email.addError('Duplicate Found');
}
}
}
Don't forget to select best answer to make our efforts visible in the developer forum.
Please mark this as solution by selecting it as best answer if this solves your problem, So that if anyone has this issue this post can help
done
Sura's answer is best solution for your requirement.
Santosh
It can't be achieved using validation rule any ways because we need to compare it with existing records.
Also the best practice to check the validation is on before insert and before update trigger actions.
Thanks.