function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Swamy PSwamy P 

Trigger and validation


    i have a situation,i.e when i update a record then it must compare previous value of name with present value of Name.Thus two Names must not be same. For this,i wrote trigger as well as validation.Both are working but when i edit record for changing the other field and i click save,again it shows error.But we dnt want that,we need logic executed only for particular Name updated.

Can anyone suggest me the logic for trigger or validation...



trigger old_New_comparison on Employee__c (after update) {
for(Employee__c e:Trigger.New){
Employee__c oldvalue=trigger.oldMap.get(;
e.Name.adderror('Please Change the Name');




AND( ISCHANGED( Name ) ,  NOT(PRIORVALUE( Name )   =    Name)  )





I hope ur requirement is to prevent the entering of same names.


Try the following out of box functionality instead of code.


1. Create a Text field - make it unique and hidden

2. Copy the name from your field to this text field using workflow field update.

3. When the user is trying to enter the same name, system takes care.



Swamy GeorgeSwamy George

hi,surekha very good idea...but i want to go by only validation...can you try it...

once check my validation also...


please clarify the requirment if your requirment is prior value of name should not be the new name value then the validation rule is enough

Swamy GeorgeSwamy George