Provide Visible No-Argument Constructors for Custom Apex Classes Used as Invocable Action Parameters
Apex classes used for invocable action parameters must have a visible no-argument constructor. The constructor must be global for packaged classes invoked from outside the package. Use API version 65.0 or earlier with the release update disabled to maintain the previous behavior.
Where: This change applies to API version 66.0 and later. This change applies to Lightning Experience and Salesforce Classic in Enterprise, Performance, Unlimited, and Developer editions.
Why: The no-argument constructor instantiates your Apex classes when Apex code, REST API, or flows call invocable actions. Constructor visibility prevents instantiation failures and run-time errors. This change was originally introduced as the “Enforcing No-Argument Constructor” release update, which is no longer enforced. If you haven't enabled that release update, this versioned change implements the requirement.
How: Provide a global no-argument constructor with appropriate visibility for your custom Apex classes used as invocable action parameters inside the package. Use the default constructor or explicitly define your own.
If your class has no explicit constructors, Apex provides an implicit no-argument constructor with the same access level as the class:
global class MyInvocableClass {
@InvocableVariable(required=true)
global String accountName;
@InvocableVariable
global Integer priority;
// No explicit constructor - Apex provides an implicit global no-argument constructor
}
When you add a constructor with parameters, Apex no longer provides the implicit no-argument constructor. Apex requires that you add a no-argument constructor with appropriate visibility:
global class MyInvocableClass {
@InvocableVariable(required=true)
global String accountName;
@InvocableVariable
global Integer priority;
// Constructor with parameters
global MyInvocableClass(String accountName, Integer priority) {
this.accountName = accountName;
this.priority = priority;
}
// Explicit no-argument constructor now required
global MyInvocableClass() {
}
}