Possible to create a generic “invocable class” per object?

My organization is starting to feel some pain around using Process Builder + Flow (error handling mostly, but also inherent Flow inefficiencies and the inability to run Flow in system context).

Thus, we’re starting to opt more for Process Builder + Invocable Apex. I’ve searched around for best practices, but haven’t found much. I would ideally not want to have a million classes, each with one specific invocable method performing one specific function. However, given the “one invocable method per class” limitation, I’m struggling to come up with an efficient way to organize these classes.

As it is, I’ve got it structured as:

  • [Object][function].cls – class which performs the specific logic
  • [Object][function]_Invocable.cls – only contains the @Invocable method and the inner class with @Invocable variables. The method calls the specific class (above)

The only idea I’ve come up with is to add a string variable to specify which actions to perform and do a bunch of IFs. Of course, that requires foreknowledge on the declarative side of the valid strings…which I suppose isn’t the end of the world.

Anyway, curious if anyone has thought of a more elegant way to handle this.

Answer

Attribution
Source : Link , Question Author : Mike , Answer Author : Community

Leave a Comment