-
Notifications
You must be signed in to change notification settings - Fork 238
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cannot disable DLRS in Apex #889
Comments
This is a good enhancement to the tools public API. Meanwhile you can customize the DLRS trigger that was generate by the tool and add an "if" statement referencing a static member variable your code controls to condition the call in the generated trigger to the RollupService. |
Good to hear! The solution we engineered was to use Custom Settings. We created an org-wide checkbox called DLRS_Switch__c with a default value of false. We also added a flag to the child trigger to check that this value was false before executing, like so:
Then, at the beginning of our process, we set the value of the checkbox to true. We run the process, then set the switch back to false, and end the process by calculating all lookups using the runJobToCalculate method. |
@delan-flywheel thanks so much for sharing meanwhile! |
Kevin O'Hara's sfdc trigger framework has a bypass API, but for triggers. I imagine that it would be very simple to implement a similar functionality. |
Thanks @renatoliveira PR merged! |
Fixed in v2.12 |
I posted this comment on the merged pull request, but on reflection realize that might not have been the best place. So- Is there documentation on usage for this feature? |
If you are talking about the Apex API, you can just use RollupService's static methods:
They are supposed to be used in the middle of your code, turning on/off rollups dynamically. For example, if you want to update a child record but don't want to update the parent's rollups. |
That's the pointer I needed. I also forgot about name spaces, which is another reason I was getting errors. Thanks! |
@mkdjns you've obviously got the bypass handler working, can you give more details how? I've called dlrs.RollupService.bypass(name) and passed in "names" using the following fields from the custom metadata settings in dlrs__LookupRollupSummary2__mdt
I've also looked in dlrs__LookupRollupSummary__c to see if I can grab the Name field from there, but there don't appear to be any records in that object All that happens is that it adds the string passed in to a set and a call to dlrs.RollupService.isBypassed() just tells you that the name passed in is in the set. It doesn't tell you if the rollup has actually been bypassed. You mention forgetting namespaces, is that where I'm failing? |
@stephenpstanley, maybe this will help. You should be able to use the Here is where it is checked,
and here is where the value is retrieved from the metadata.
|
Thanks - they are definitely stored in the custom metadata setting, but I'm still getting Too Many SOQL 101 errors even with all the rollups bypassed as dlrs and some triggers are doing too many queries in my test class. Dlrs is looking to see which are active and running 50+ queries even with the rollup meta data disabled :-( |
Yep doesn't work for me either. Compiles and runs, but I see in logs DLRS is still running. Using same names as I use to schedule jobs using Apex. |
Is there a way to disable (set dlrs__Active__c to false) our rollups for the duration of a specific trigger and then re-enable them at the end?
We have built a process that makes small edits to a large number of records, and we have run into CPU timeout issues partially because there are a lot of rollup fields involved.
We deduced that rollup fields were a contributing factor. This was confirmed when we manually disabled the rollups and tried to run the process. It worked, and then we re-enabled the rollups and clicked 'Calculate'.
We would like to automate this manual disabling, enabling, and one-time calculation of the lookups. Our hunch was to add code disabling the lookup fields (setting dlrs_Active__c to false) to start the process, and then at the end of the process reactivating them and then manually calculating the rollups once, now that the thousands of records have been changed.
This hasn't worked because DML operations are not permitted on dlrs__LookupRollupSummary2__mdt, where our lookup information seems to be. We tried to work with the dlrs.CustomMetadataService methods to see if there was promise there, but we have run into a problem of 'Type is not visible: dlrs.CustomMetadataService'.
Any insight on how we should approach this problem would be greatly appreciated. Is there a method we are missing?
Thanks,
The text was updated successfully, but these errors were encountered: