PDI · Question #165
What are three considerations when using the @InvocableMethod annotation in Apex? Choose 3 answers
The correct answer is C. A method using the @InvocableMethod annotation must be declared as static D. A method using the @InvocableMethod annotation can be declared as Public or Global. E. Only one method using the @InvocableMethod annotqation can be defined per Apex class. Invocable methods must be static, can be public or global, and only one such method is allowed per Apex class.
Question
What are three considerations when using the @InvocableMethod annotation in Apex? Choose 3 answers
Options
- AA method using the @InvocableMethod annotation must define a return value.
- BA method using the @InvocableMethod annotation can have multiple input parameters.
- CA method using the @InvocableMethod annotation must be declared as static
- DA method using the @InvocableMethod annotation can be declared as Public or Global.
- EOnly one method using the @InvocableMethod annotqation can be defined per Apex class.
How the community answered
(29 responses)- A3% (1)
- B3% (1)
- C93% (27)
Why each option
Invocable methods must be static, can be public or global, and only one such method is allowed per Apex class.
An invocable method is not required to define a return value and can have a `void` return type, although it can return a `List`.
An invocable method can only have one input parameter, which must be a `List` of a primitive, sObject, or user-defined type.
Invocable methods are designed to be called from external processes (like Flow or Process Builder) without an instance of the class, thus they must be declared static.
For invocable methods to be accessible to external processes, they must have either public or global access modifiers.
Salesforce restricts the use of @InvocableMethod to a single method per Apex class to ensure clear entry points and predictability when invoked from declarative tools.
Concept tested: Apex Invocable Methods
Source: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_annotation_InvocableMethod.htm
Topics
Community Discussion
No community discussion yet for this question.