EDIT: on further research what I want is the Apex equivalent of Collection Filters I have looked at Query Utils but other than the complexity there seems to be lots of "DON'T USE THIS UNDER RISK OF SUDDEN KERPLODING" in the documentation. This needs to be fully dynamic so I can't just call a flow and pass the list and let the flow do it.

What I want to do is if an inserted account meets certain criteria as defined in a tag object it would attach the tag to the account so my initial thought is I would have a tag filter object with a string and object.

Filter__c = "Name = 'Steve' AND Value__c > 100000 AND Level__c > 1"
Object__c = "'Account'"

Then all I would do is on insert I would loop through all of the filters and run a SOQL query for each filter.

[SELECT Id FROM Account WHERE Name = 'Steve' AND Value__c > 100000 AND Level__c > 1 AND Id IN:listofinsertedaccounts]

But naturally, this isn't very efficient especially as I already have the objects in all their glory so I was wanting to know if anyone thought of a better way of doing this? has anyone built a query resolver for this sort of issue or am I trailblazing again.

  • Applying this sort of filter in memory is something I have seen before, but not to indeterminate number of records. Are you not able to pre-select a candidate pool?
    – Adrian Larson
    Jun 29, 2022 at 0:27
  • I can get the list of Accounts that have been inserted max of 200 yay! but the issue is that there are an indeterminate amount of potential topics that COULD apply to them. My current terrible solution is to do a batch apex through all the criteria 200 at a time using the results of each topic query to fill out the topics it's just it seems very wasteful when I already have all of the possible objects I want to test against to re-query them. Jun 29, 2022 at 11:17
  • I can tell you that a generic tagging engine is possible, as I have built something similar. That said, it is a huge effort that requires several layers. It's too big a project to lay out completely here. Note that things get considerably more complicated if you want to support cross-object field evaluation. If you do, then supporting insert evaluation is significantly more expensive than update evaluation.
    – Adrian Larson
    Jun 30, 2022 at 0:26
  • well I need to do it on both as in theory an account use to be high value but maybe it isn't now and the tag needs to be removed. Jun 30, 2022 at 14:03

1 Answer 1


There are a few repos that may do what you want:

The doc on QueryUtils says it is for Salesforce Connect

  • hmmm, I'll probably have to look at rolling my own way of converting a SOQL query over to one of these or make my own referencing this. We have salesforce connect I know it's not 100% intended but we do have access. Jun 29, 2022 at 15:23

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .