Closed eggletm closed 7 years ago
Thanks Martin, are these two objects not already in a master detail relationship? If so, platform rollup summaries should suffice without this tool? If not, then yeah some kind of enhancement to bypass the use of CurrencyType in this context might be needed (since it seems the platform blogs apex code running in this code directly). I'm also not sure at this stage the impact of that tbh, the tool references that table for good reason, so would need to check that.
Hi Andrew Thank you for the response. The two objects are not in a master detail relationship, so we cannot rely on the platform rollups. (FYI Objects are FF PSA Expense Report & Expense) Thanks for looking at it as an enhancement. Martin
Just wanted to add that my company has a Partner Portal issue with this too on a client site. We tried setting the rollup to run in System mode but that does not seem to prevent the error from coming up. This is also a lookup relationship, not Master-Detail.
Really need this feature.
Here is the exact error and code lines to help on identifying the code.
Thank you.
execution of AfterUpdate caused by: System.QueryException: sObject type 'CurrencyType' is not supported. Class.dlrs.LREngine.convertCurrency: line 72, column 1 Class.dlrs.LREngine.rollUp: line 248, column 1 Class.dlrs.LREngine.rollUp: line 108, column 1 Class.dlrs.RollupService.updateMasterRollupsTrigger: line 967, column 1 Class.dlrs.RollupService.handleRollups: line 824, column 1 Class.dlrs.RollupService.triggerHandler: line 302, column 1
Ultimately what is the root cause of this? Is it because the convertCurrency code is running in the User context instead of System?
Ok i think the source of the problem is your running in an org without multi-currency enabled? Is this the case? https://developer.salesforce.com/docs/atlas.en-us.sfFieldRef.meta/sfFieldRef/salesforce_field_reference_CurrencyType.htm
Hi Andrew, no the reverse. It worked fine without multi-currency. This error started happening when multi-currency was enabled. Here's more detail:
It's a Partner Community. We have a currency field on a child object with a DLRS real-time rollup sum to a currency field on the parent object. The rollup runs in System mode. Users of the Partner Community are able to edit the child object.
When multi-currency was not enabled yet, there was no issue.
After multi-currency was enabled, this error started appearing when a Community user edits the child. However when a user with a full Salesforce licence edits the same child, the error does not throw.
Looking at the stack trace I note that:
So I can conclude the query select IsoCode, ConversionRate from CurrencyType where IsActive = true is running in with sharing mode. Evidently Salesforce does not allow Community users to query this object in a with sharing context. Would the problem be solved by forcing that currency query to run in without sharing mode, or at least to abide by the selection of User/System in the rollup definition?
It may well be you haven't seen this error outside Communities because users with standard Salesforce licenses have access to the CurrencyType table.
I just wanted to add, I was able to demonstrate in our sandbox a bare minimal example of this issue. I used one line of Apex to execute a bare minimum query against CurrencyType under a few scenarios: SObject[] ls = [SELECT IsoCode FROM CurrencyType]; We disabled the DLRS rollup during these tests.
Inserted into the child trigger file directly, this line does not cause any trouble when the Community user edits the child record.
If this line is in a method of a "without sharing" class and then the method is called from the child trigger, it still does not cause any trouble when the Community user edits the child record.
If this line is in a method of a "with sharing" class and then the method is called from the child trigger, it throws the same exception seen here: System.QueryException: sObject type 'CurrencyType' is not supported.
Wow some great detective work here @camisotro, digesting this...
There is a Calculating Sharing field on the rollup, would setting this to System (runs the rollup query in without sharing mode) help given your analysis i wonder?
I am already setting it to System and it still throws the exception. As you will see in my analysis above, the LREngine.convertCurrency method always runs this query in a with sharing context so it still hits the exception.
Oooooh yes, sorry, its late, should have read that better. Ok..... so yes, i have enough to go on for a fix here. Nice job again! 👍
I have wrapped just the LREngine.convertCurrency method in a "without sharing" context.
v2.9
Hi We are using a Community Portal for contractors to log Time & Expense on to FF PSA at the backend. We are using DLRS to just count the number of associated Expenses to Expense Report using the Amount field (as it should be populated). When our users try and submit their expenses we get the following error: dlrs_pse_ExpenseTrigger: execution of AfterInsert caused by: System.QueryException: sObject type 'CurrencyType' is not supported. (dlrs)
I have got a work around for now, to count the Type field, but if we want to create any other roll ups using the Amount field we get the above error.
Any thoughts? Thanks Martin