fbpx
    1. Blog
    2. Custom Permissions, Validation Rules and Apex CPU Limits

    Custom Permissions, Validation Rules and Apex CPU Limits

    • We had a requirement recently to allow a subset of users (not aligned to specific profiles) to be able to move an Stage field forward but not backwards. We thought this was a great use case for the Custom Permissions as referenced by Brian Kwong aka @salesforceWizard here http://thewizardnews.com/2015/01/08/custom-permissions-the-joy-of-flexibility-in-validation-rules-and-workflow/ and @andyinthecloud here https://andyinthecloud.com/2015/01/14/creating-assigning-and-checking-custom-permissions/

      We had the Validation rule working, however as the feature was being used more and more by our customer, more and more data was being updated simultaneously (I won’t go into the details but suffice to say more that 100 records being updated in one DML, via a Trigger, Class and Helper Class was becoming common).

      One day we started to get Apex CPU limit Exceeded errors when records were being updated and we started to troubleshoot the problem. It was whilst reviewing Timeline on Debug logs that we observed that 50% of the time was being used in Validation.

      After lots of trial an error we established that it was the use of NOT($Permission.Move_Element_Status_Backwards) which was included in the Validation rule that caused the problems. We decided to verify this by doing the following:

      First test the very simple validation rule

      1. Create New Object
      2. Create Validation Rule 1 – Formula value = false – i.e it will never fail but I needed at least one validation rule to see in the debug logs
      3. Insert 100 records using any bulk method (I used Dataloader).

      When I analysed the results this is what we got:

    • Notice the total duration was only 14.91ms

      Next is to test the #Permission Validation Rule

      1. Disable Validation Rule 1
      2. Create Custom Permission – Test
      3. Create Validation Rule 2 – Formula value = $Permission.Test
      4. Enable Validation Rule 2
      5. Insert 100 records using any bulk method (I used Dataloader).

      When I analysed the results this is what we got:

    • Notice the total duration was a massive 3,811.39ms

      This is worrying and I’m currently trying to validate from Salesforce if this is a Known Issue or Bug or a Limitation of Custom Permissions.

      Feel free to join the conversation here on twitter

      Adendum
      Johan Yu https://twitter.com/simplysfdc has also tested the use of Custom Permissions by loading 1,000 Leads and observed a 70% increase in the time taken to load the data.

  • 10 ways to be more organised in 2021

    At some point in our lives, most of us have made a resolution to be more organised. For many it is likely to have coincided with the start of a new year, whether calendar, financial or the school year. However, being organised involves more than simply aiming to be that way.

    Learn More

  • 2020: Highlights, challenges and looking forward

    When the clocks ticked over to 2020 on January 1 this year, no-one could have known what a tumultuous year it would turn out to be. If you’d told the party revellers that within 4 months, the world would be gripped by a health epidemic and borders would close, events would be cancelled, and people’s movements restricted due to lockdowns, they would have no doubt looked at you like you had already partied too much.

    Learn More

  • Confessions of a people manager

    So here’s a secret: when the energy in a team is positive, collectively the team can achieve something astounding. People energised around an ambitious goal transform into a powerful force.

    Learn More