When deploying apex classes, a user may run into an odd error: Error: Compile Error: Invalid constructor name
.
How to solve Invalid constructor name
Upon initial inspection, this error may be misleading. The class in question contains a working constructor or a new method was added that is not a constructor.
What gives?
Normally, this error indicates that a new method was added without adding the return type.
Example:
|
|
To fix this, simply add the return type to the method:
|
|
Why does this error happen?
When a return type is omitted, the method is interpreted as a constructor because constructors do not contain return types.