Skip to content
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

Support for Currency Roll Ups with Community Portal Users #454

Closed
eggletm opened this issue Jan 29, 2017 · 15 comments
Closed

Support for Currency Roll Ups with Community Portal Users #454

eggletm opened this issue Jan 29, 2017 · 15 comments

Comments

@eggletm
Copy link

eggletm commented Jan 29, 2017

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

@afawcett
Copy link
Collaborator

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.

@eggletm
Copy link
Author

eggletm commented Feb 21, 2017

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

@camisotro
Copy link

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.

@mohuzi
Copy link

mohuzi commented Feb 24, 2017

Really need this feature.

@mohuzi
Copy link

mohuzi commented Feb 24, 2017

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

@camisotro
Copy link

Ultimately what is the root cause of this? Is it because the convertCurrency code is running in the User context instead of System?

@afawcett
Copy link
Collaborator

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

@camisotro
Copy link

camisotro commented Feb 26, 2017

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:

  • LREngine.convertCurrency is located in a class with no with/without sharing annotation and uses Database.query to access this currency table (will inherit sharing annotation of calling class).
  • That method is called from LREngine.rollup located in the same class.
  • That method is called from RollupService.updateMasterRollupsTrigger which is located definitely in a with sharing class.

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.

@camisotro
Copy link

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.

@afawcett
Copy link
Collaborator

afawcett commented Mar 8, 2017

Wow some great detective work here @camisotro, digesting this...

@afawcett
Copy link
Collaborator

afawcett commented Mar 8, 2017

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?

@camisotro
Copy link

camisotro commented Mar 8, 2017

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.

@afawcett
Copy link
Collaborator

afawcett commented Mar 8, 2017

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! 👍

@afawcett
Copy link
Collaborator

I have wrapped just the LREngine.convertCurrency method in a "without sharing" context.

@afawcett
Copy link
Collaborator

v2.9

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants