2

I would like to know if there are any best practices when building multiple @InvocableMethods for a Salesforce flow. As of now, Salesforce limits only 1 @InvocableMethod per apex class.

Only one method per type can be defined with: InvocableMethod

Is my only option to create an Apex class for each @InvocableMethod?

1 Answer 1

4

For what it's worth, I've complained to at least one product manager (PM) at salesforce.com about this restriction. I think it's silly that we can't have multiple methods in the same class, given the UI could just list the methods. That said, you are correct in assuming that, at least for now, you must use a separate class for each invocable method. I guess the only real "best practices" that come to mind are to name your classes consistently so that they make sense in the UI, make sure you use the appropriate category for them to appear in, and provide a description.

5
  • You're right, this is silly! Thanks for confirming at least.
    – apz
    Commented Dec 20, 2022 at 16:18
  • 2
    The other recommendation I have is to have these methods delegate to a separate class to do the actual processing. That way, if there are a number of related invocable methods their implementation code can all be in one class, with the invocable method classes simply calling on through to this common class.
    – Phil W
    Commented Dec 20, 2022 at 19:44
  • That's a good idea, I'll give it a shot. Thanks!
    – apz
    Commented Dec 22, 2022 at 17:03
  • 1
    There is good idea-- feel free to upvote ideas.salesforce.com/s/idea/a0B8W00000GdeuIUAR/…
    – kurunve
    Commented Jan 19 at 10:41
  • 1
    @kurunve codefriar and I came up with a way to work within the limitations. See Kevin's blog post for more info. Would be great to have native support, though.
    – sfdcfox
    Commented Jan 19 at 10:46

You must log in to answer this question.

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