Timeline for Can you conditionally build-up a static SOQL query in Apex?
Current License: CC BY-SA 4.0
7 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Feb 28, 2023 at 1:39 | comment | added | kennyc | I'll need to verify this, but if a static SOQL query (in an Apex class) references a custom object, and I try to delete that custom object from my org, I was under the impression Salesforce would warn me that the custom object has dependencies and is thus "in-use". The dependency checker must know this because the objects and fields it lists on that Setup page, match exactly the objects and fields in my Apex class' static query. Presumably I would lose that dependency checking if I switch to the string-based, dynamic queries. At least that's what I thought... | |
Feb 28, 2023 at 0:22 | comment | added | zaitsman | @kennyc that 'dependencies' you are talking about are part of DDL in a conventional database and what you are querying is DML. In other words, they are not the same at all. And yes, anything you can query statically you can also query dynamically including functions, aggregates, and relationships. | |
Feb 27, 2023 at 23:05 | comment | added | kennyc | If I go Setup - Apex Classes - [Class] - Show Dependencies, it will list the Objects and Fields this class depends on. I'm assuming that's because a static SOQL query exposes that dependency. Because a dynamic query is really just a string, I was a worried I'd lose this dependency tracking. We might be undertaking a lot of refactoring in the near future, so having Salesforce know about dependencies would be a huge help. | |
Feb 27, 2023 at 22:48 | comment | added | Derek F | @kennyc I'm not entirely sure what you mean here. Are you talking about something like pulling in dependencies for changesets? Or perhaps the "where is this used" button that appears in some places? If so, then the answer is no in both of those cases. | |
Feb 27, 2023 at 21:48 | comment | added | kennyc | When using dynamic SOQL, can Salesforce still resolve Object and field dependencies for an Apex class or is that support now lost? | |
Feb 27, 2023 at 21:42 | vote | accept | kennyc | ||
Feb 27, 2023 at 20:42 | history | answered | Derek F | CC BY-SA 4.0 |