Is there a possibilty in Salesforce from trigger beforeInsert how to stop the insert in the database table.


1 Answer 1


Using the SObject method addError on a record will prevent any DML operations (including inserts) from occurring on that record.

trigger preventContactInserts on Contact (before insert) {
  for (Contact c : Trigger.new) {
    if (c.FirstName=='Brian' && c.LastName=='Mansfield') {
      c.addError('You can't insert this record.');

Not the answer you're looking for? Browse other questions tagged .