I keep seeing lots of questions about how to bulkify queries (often in the context of a trigger) based on data from a collection of input objects.

We are all aware of the typical approaches such as the use of building one or more collection(s) of values from the inputs to query against then the use of a Map (perhaps using an Id key, or even Object[] key as I have suggested here) to make looking up that bulk data efficient when processing the input objects, but I can't seem to find a good "canonical" Q&A explaining the common patterns.

Having one would help reduce the burden on the community by making it easy to mark questions as duplicates but also by giving developers a great resource to find using their favourite search engine.

What's the process for creating one of these? And does anyone have other favourite patterns that this could include?

1 Answer 1


What's the process for creating one of these?

Start writing, and loop in any interested contributors!

Feel free to copy the basic text framework from any of the existing canonical questions.

When you get a first draft to a point where you're happy with it (this can be an iterative process), go ahead and post it. Please consider marking your answer as a Community Wiki (as the other canonical QAs are); this makes it easier for the community to develop it rather than adding more answers. If you do so, ping a moderator to have the whole question marked as a Community Wiki.

I'd be happy to contribute and I think this is a good idea that will provide value to the community.

  • I get the feeling from what you're saying these are worked on, iteratively, in the standard SFSE Q&A list (at least once drafted to a certain point)? Is there a less visible way to share drafts with other possible contributors? Also, how to "loop in interested contributors"? (Sorry, I know a comment isn't really the right place for these additional questions but was hoping you could add clarifications in your answer.)
    – Phil W
    Oct 6, 2020 at 16:08
  • @PhilW If mods can migrate things from meta to the main site (don't know if this is possible), then we could start with new canonical-qa questions being fleshed out here in meta.
    – Derek F
    Oct 6, 2020 at 16:11
  • No, no, good questions all. When we did the first canonical QAs they were written up in Markdown in a GitHub repository by me and Pranay Jaiswal, then posted for the rest of the community to edit and improve. That process was a little heavy. If you, or anyone else, is comfortable throwing together an MVP first draft, just editing it in the Q&A feels viable to me. As for finding collaborators - hopefully they will chime in here.
    – David Reed
    Oct 6, 2020 at 16:18
  • @DavidReed any thoughts on Derek F's suggestion? Could we do this drafting and collaboration here, or is that an abuse of meta?
    – Phil W
    Oct 6, 2020 at 16:26
  • I don't have any problem with it myself. Maybe add a framing note and link to this question to explain what's going on. I can't actually move it from Meta to Main, but it's easy enough to copy the developed text.
    – David Reed
    Oct 6, 2020 at 16:27
  • I'd like to underscore @DavidReed's suggestion to make this a community wiki. And did this actually happen? I'd love to see it. With the launching of the Apex Recipes sample app last week, I think there would likely be some good points of reference to link to there.
    – pchittum
    Oct 17, 2020 at 10:36
  • @pchittum It's now posted as a Community Wiki under the canonical-qa tag on main.
    – David Reed
    Oct 17, 2020 at 22:16
  • 1
    @pchittum nice mention of Apex Recipes. Found the github repo and had a look. Very much dislike the "best practice" exposed in the AccountTrigger since this requires the trigger helper to directly reference the Trigger.old/new and similar data, which means the code cannot easily be tested outside the context of an actual DML operation. Not sure where to provide that feedback though.
    – Phil W
    Oct 19, 2020 at 12:55
  • 1
    @PhilW, I'd encourage you to file an issue and begin the discussion right there in the repo. Thanks for the feedback. Always helpful. My guess is the best kind of issue to file is a "Feature Request" issue.
    – pchittum
    Oct 19, 2020 at 19:18

You must log in to answer this question.

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