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

      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.

  • Life in Actual Lockdown – Reflections from the Philippines

    The word lockdown has been used to describe many of the restrictions that have been put in place due to COVID-19. However, while many Australians say we have been living in lockdown, the reality is we still had a fair bit of freedom, even before restrictions began easing.

    Learn More

  • Struggling for motivation? You’re not alone!

    It’s fair to say that all of us have struggled with motivation at some stage throughout the current situation. Whether it is on the work front or with exercise, maintaining connections, home schooling, or the multitude of other issues we come across in our day, most of us have had moments of blah. 

    Our Operations Manager Karen, is no different. Despite being one of the ‘lucky ones’, Karen has still witnessed the financial pain of workers and businesses and knows that even those who are still operating face a future in which planning will play a key role.  

    Learn More

  • The Cost of Doing Nothing

    With so much uncertainty in the economy at the moment, ‘hunkering down’ seems like the obvious solution to saving money. However, as our National Sales Manager notes, this approach may not deliver the desired value in the long run.

    Learn More