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

Hi,

    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:

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

}
}

 

Validation:

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

 

SurekaSureka

Hi,

 

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.

 

Thanks

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...

avijchakavijchak

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

Hi