Activity Forums Salesforce® Discussions Is there a way to force execution of all validation rules?

  • Is there a way to force execution of all validation rules?

    Posted by Nitish on April 30, 2016 at 5:14 pm

    Is there a way to force execution of all validation rules? Ultimately, I'd like to test an oppty against VR's, just as if you Edit/Saved, but without modifying its timestamps.

    That way I can see how reported oppties are failing, without having to edit/change/touch live data.

    Gourav replied 8 years, 5 months ago 2 Members · 1 Reply
  • 1 Reply
  • Gourav

    Member
    June 8, 2016 at 10:53 am

    I don't think there is any out-of-the box way to do this. Maybe you can quickly do this with some anonymous Apex code:

    List<Opportunity> failingOppys = new List<Opportunity> ();
    for (Opportunity o : [SELECT Id FROM Opportunity]) // Here you should select all fields that may cause validation
    {
    Opportunity ocl = o.Clone (false, true, false, false);
    try {
    insert ocl;
    delete ocl;
    }
    catch (Exception e)
    {
    failingOppys.add (o);
    }
    }
    System.debug (failingOppys);
    This code is non-bulkified so you may hit some Apex limits after 100 records or so. Let me know if this approach could work for you and perhaps we could come up with a bulkified/batched version of it. How many opportunity records are we talking about?

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos