You need to sign in to do that
Don't have an account?

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) )
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
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
Hi avijchak,
once i give name as mr.faulk,than i edit record and save the record,while it saving...it shows an error i.e,
"Name is not changed"...prior value must not equal to present value for that particular field.