Missed opportunity: defaultValue and placeholderText modifiers
Why is this an issue?
The @InvocableVariable annotation supports defaultValue and placeholderText modifiers that improve the Flow Builder experience. When configuring invocable actions, these modifiers:
defaultValue: Pre-populates the input with a sensible default
placeholderText: Shows guidance text in empty input fields
Without these modifiers, Flow builders must guess appropriate values.
Note that defaultValue cannot be used together with required β Salesforce throws an error when both are present. For required variables, only placeholderText is expected.
Examples
Example of incorrect code:
public class CreateTaskAction {
@InvocableVariable(label='Subject')
public String subject;
@InvocableVariable(label='Priority')
public String priority;
}
Example of correct code:
public class CreateTaskAction {
@InvocableVariable(label='Subject' defaultValue='Follow Up' placeholderText='Enter task subject')
public String subject;
@InvocableVariable(label='Priority' defaultValue='Normal' placeholderText='High, Normal, or Low')
public String priority;
}
Example of correct code when using required (no defaultValue needed):
public class CreateTaskAction {
@InvocableVariable(label='Account Id' required=true placeholderText='Enter the Account record Id')
public String accountId;
}
How can I fix violations?
Add defaultValue and placeholderText to @InvocableVariable annotations:
Use
defaultValueto pre-populate the input with a sensible defaultUse
placeholderTextto provide guidance on expected inputIf the variable uses
required, omitdefaultValue(they are incompatible) and only addplaceholderText
When should I disable this rule?
You may dismiss specific violations for variables where defaults or placeholders are not applicable.
Resources
