Activity Forums Salesforce® Discussions Can we avoid deletion of records through validation rules?

  • Manpreet

    Member
    April 27, 2018 at 11:29 am

    Hi saurabh,

    No. Validation rules fire in insert and update operation.

    Thanks.

  • Aman

    Member
    May 1, 2018 at 8:00 am

    Hi Saurabh,
    I think you can only do this with a validation rule if the object in question is the child in a master-detail relationship. If so:

    Set up a rollup summary field on the parent object which counts the number of child records.
    Set up a validation rule on the parent object which prevents the rollup field value from decreasing:

    If that doesn't work, a simple trigger will:

    trigger DeletePrevention on MyObject__c (before delete) {

    for (MyObject__c mo : Trigger.old) {

    mo.addError('Unable to delete record!');
    }
    }

    Thanks

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos