apex-enterprise-patterns / at4dx

Advanced Techniques for Salesforce DX Adoption Framework

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Selector layer questions

mateuszzw opened this issue · comments

Hi @ImJohnMDaniel @stohn777 ,

I would like to ask about 2 functionalities that I tried to use, but I couldn't find the built-in solution:

  1. Aggregate Queries - is there any way to do that within the selector layer without direct/dynamic queries? I found the information that it's one of the limitations of the AT4DX, but I'd like to know whether there was any specific reason it's not implemented.
  2. Polymorphic fields TYPEOF clause - it's available since API 46.0, but I couldn't find any built-in solution to use it with query factory. Are there any plans to implement it?

I really appreciate all the work you've been doing with AT4DX!

Best regards,
Matt

G'day @mateuszzw, thanks for reaching out.

Regarding your questions:

Aggregate Queries - is there any way to do that within the selector layer without direct/dynamic queries? I found the information that it's one of the limitations of the AT4DX, but I'd like to know whether there was any specific reason it's not implemented.

  • Just to be clear, the Selector Pattern is part of the FFLIB Apex Commons framework and not part of AT4DX per se.
  • In the Apex Commons framework, the Selector Pattern builds standard queries using the fflib_QueryFactory. The query factory though does not build aggregate queries.
  • In general, when there is an Aggregate Query requirement, it is general practice to code the inline query directly in a selector class method. This way, you are still able to centralize the queries on the Sobject in its selector class.

Polymorphic fields TYPEOF clause - it's available since API 46.0, but I couldn't find any built-in solution to use it with query factory. Are there any plans to implement it?

  • As far as I know, we have not had a request for support of TYPEOF. It would be an interesting challenge to implement in the query factory. I would have to give it some more thought though. I would recommend opening a feature request over on the FFLIB Apex Commons project so that the request is at least documented. No promises on when it will happen though. Having said that, we certainly welcome if you would like to make an attempt to add that feature to the query factory.

I hope this help.

Hi @ImJohnMDaniel,

Thank you for your time on this topic!
I just wanted to elaborate my view on these matters:

In general, when there is an Aggregate Query requirement, it is general practice to code the inline query directly in a selector class method. This way, you are still able to centralize the queries on the Sobject in its selector class.

I'm aware that it's a part of the Apex Commons framework, however I just don't find it elegant to have a builder pattern used for "regular" queries, but have inline query for aggregate ones. I just thought that it would be nice to have some sort of AggregateQueryFactory that would extend the fflib_QueryFactory.

As far as I know, we have not had a request for support of TYPEOF. It would be an interesting challenge to implement in the query factory. I would have to give it some more thought though. I would recommend opening a feature request over on the FFLIB Apex Commons project so that the request is at least documented. No promises on when it will happen though. Having said that, we certainly welcome if you would like to make an attempt to add that feature to the query factory.

I'll speak with one of my colleagues as we actually thought of implementing it ourselves.

@mateuszzw --

re: Your comment about a potential AggregateQueryFactory is definitely a good idea. There just hasn't been enough of a need for such a factory for someone to actually create it. Having said that, if you are interest, please feel free to make an attempt and open a PR when you feel you are ready.

re: TYPEOF -- Again, if you have an idea about how to implement, we would love to see a PR with addition when you get a chance.

Thanks for the questions. Cheers!