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.

  • [adinserter block='9']
  • 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

Steps to Connect Pardot to Salesforce

Steps to Connect Pardot to Salesforce

Blog in

Steps to Integrate Salesforce and Pardot: There are some steps to install Pardot in salesforce 1- Click on this link https://login.salesforce.com/?ec=302&startURL=%2Fpackaging%2FinstallPackage.apexp%3Fp0%3D04t1W000000U7P8(production) https://test.salesforce.com/?ec=302&startURL=%2Fpackaging%2FinstallPackage.apexp%3Fp0%3D04t1W000000U7P8 (sandbox) 2- After…

Popular Salesforce Videos