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
Rajesh Rajesh KumarRajesh 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');
}
}
}
Raj VakatiRaj Vakati
Its a Trigger to check the LastName is "INVALIDNAME" or not. .If Its an INVALIDNAME then it will throw an error and 

You no need to write the trigger for this and you can able to do it using the validation 
Ajay K DubediAjay K Dubedi
Hi Rajesh
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