Skip to main content

Code reviews rule: Missed opportunity: defaultValue and placeholderText modifiers

Written by David Martin
Updated today

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 defaultValue to pre-populate the input with a sensible default

  • Use placeholderText to provide guidance on expected input

  • If the variable uses required, omit defaultValue (they are incompatible) and only add placeholderText

When should I disable this rule?

You may dismiss specific violations for variables where defaults or placeholders are not applicable.

Resources

Did this answer your question?