Lock Down DLRS Fields and Make DLRS Play Nicely with Validation Rules

So you have a DLRS field and you don’t want your users to update the field as it should always be controlled by DLRS.  This can be taken care of via Field Level Security (FLS).  DLRS Runs in Apex and Apex runs in system mode meaning that it doesn’t care about FLS or anything like that.  This means you can set the field to Read-Only for all profiles and DLRS will still be able to update the field no matter what user triggers the DLRS.

The other bonus to this is you can easily set DLRS fields to bypass Validation Rules.  We now know that the DLRS field can ONLY be updated by a system process (Apex, Workflow Rule, Process Builder, Flow launched from Process Builder) so we can write the following into your validation rules.  NOT(ISCHANGED(DLRS_FIELD__C)), so say the field isnt changed we then end up with NOT(FALSE), this becomes TRUE so your Validation rule fires as it should.  But now when DLRS fires we end up with NOT(TRUE), this becomes False and the validation rule is bypassed so DLRS can keep doing its thing even to records that might be locked by validation rules.

4 thoughts on “Lock Down DLRS Fields and Make DLRS Play Nicely with Validation Rules

  1. Aaron Goldblatt

    Hey Dan,

    I’ve got an interesting situation/issue with DRLS tool. I’ve created a custom object called ‘Year KPI’ that tracks metrics about Opportunities for each Agent. Therefore, one Agent may have many Year KPI records if they’ve been with our Company for a while. The issue at hand occurs during the transition point between years. Once we go from 2019 to 2020, all Open Opportunities should be updated so they point to the 2020 Year KPI rather than the 2019. However, we want to LOCK the 2019 KPI record and prevent DLRS from changing any values. I have yet to figure out a way to successfully change the child objects (Opportunities) lookup field to the new Year KPI but lock the previous values. Any ideas here?

    Reply
    1. Dan Post author

      So let me see if I have this correct

      Parent KPI
      Record 1 – 2019 – DLRS Field
      Record 2 – 2020 – DLRS Field

      Child
      Opps pointed to either KPI 1 or 2

      You update opps to KPI 2 in 2020 and then that triggers dlrs and now KPI 1 got updated and womp womp not what you wanted.

      Now KPI 2 is correct but KPI 1 is wrong.

      So this is tricky. Can you post this to the community so others can pitch in?

      My kinda meh solution would be new field called end of year. Move DLRS field values over come end of year. Then use a formula where if year(today())>KPIyear show static field else show dynamic dlrs field. Then you use that formula field for reporting.

      Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.