You need to sign in to do that
Don't have an account?
Rajesh Rajesh Kumar
Exaplain this Question
How it works ?
trigger RestrictContactByName on Contact (before insert, before update) {
//check contacts prior to insert or update for invalid data
For (Contact c : Trigger.New) {
if(c.LastName == 'INVALIDNAME') { //invalidname is invalid
c.AddError('The Last Name "'+c.LastName+'" is not allowed for DML');
}
}
}
trigger RestrictContactByName on Contact (before insert, before update) {
//check contacts prior to insert or update for invalid data
For (Contact c : Trigger.New) {
if(c.LastName == 'INVALIDNAME') { //invalidname is invalid
c.AddError('The Last Name "'+c.LastName+'" is not allowed for DML');
}
}
}
You no need to write the trigger for this and you can able to do it using the validation
This code help to check contact last name is not 'INVALIDNAME' if yes than it will raise an error 'The Last Name "'+c.LastName+'" is not allowed for DML' . And this trigger fire before insert and before update the contact.
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks,
Ajay Dubedi