LoadFormData Class

Retrieve records related to the tokenized record id, and populate the values of a preference form.

Namespace

Pref_center

Example

Use methods in the LoadFormData class to set available and selected values in different form components:

1List<System.SelectOption> picklistOptions = new List<System.SelectOption>();
2picklistOptions.add(new System.SelectOption('optIn', 'Opt In'));
3picklistOptions.add(new System.SelectOption('optOut', 'Opt Out'));
4
5// Set the available options for the picklist
6loadFormData.setOptions('myPicklist', picklistOptions);
7// Add an option to the existing options for the picklist
8loadFormData.addOption('myPicklist', 'optOutAll', 'Opt Out All');
9// Select the 'optIn' option in the picklist
10loadFormData.setSelectedOption('myPicklist', 'optIn');
11
12
13List<System.SelectOption> checkboxOptions = new List<System.SelectOption>();
14checkboxOptions.add(new System.SelectOption('yes', 'Yes'));
15checkboxOptions.add(new System.SelectOption('no', 'No'));
16
17
18// Set available options for the checkbox group
19loadFormData.setOptions('myCheckbox', checkboxOptions);
20// Select the 'yes' option in the checkbox group
21loadFormData.addSelectedOption('myCheckbox', 'yes');
22// Also select the 'no' option in the checkbox group
23loadFormData.addSelectedOption('myCheckbox', 'no');
24// Another way to select both the 'yes' and 'no' options in the checkbox group
25loadFormData.setSelectedOptions('myCheckbox', new List<String>{'yes', 'no'});
26
27
28// Fill the value in the text input
29loadFormData.setTextValue('myTextInput', 'admin@salesforce.com');
30// Set the hint text for the text input
31loadFormData.setTextHint('myTextInput', 'Email Address');
32
33
34// Set the label for the button
35loadFormData.setButtonLabel('myButton', 'Save Preferences');

LoadFormData Constructors

The following are constructors for LoadFormData.

LoadFormData(data)

Creates an instance of the LoadFormData class for running tests on any custom Apex classes you create for Preference Manager.

Signature

public LoadFormData(Map<String,pref_center.FieldProperties> data)

Parameters

data
Type: Map<String,pref_center.FieldProperties>Map
Maps preference form data from the field ID to the field properties.

Usage

This constructor is available in API version 56.0 and later.

LoadFormData Methods

The following are methods for LoadFormData.

addOption(fieldId, value, label)

Add an option for a checkbox, picklist, or radio button field in a preference form using the label and value.

Signature

public void addOption(String fieldId, String value, String label)

Parameters

fieldId
Type: String
Identifies a field in the preference form.
value
Type: String
Represents the selection or text entered in a preference form field.
label
Type: String
The label for the value of a field in a preference form.

Return Value

Type: void

addOption(fieldId, option)

Add a defined, selectable option for a checkbox, picklist, or radio button field in a preference form.

Signature

public void addOption(String fieldId, System.SelectOption option)

Parameters

fieldId
Type: String
Identifies a field in the preference form.
option
Type: System.SelectOption
The option selected on a field in the preference form.

Return Value

Type: void

addSelectedOption(fieldId, option)

Add a selected option for a checkbox field in a preference form. This requires the field on the form to have a defined option with a set value.

Signature

public void addSelectedOption(String fieldId, String option)

Parameters

fieldId
Type: String
Identifies a field in the preference form.
option
Type: String
The selectable option being added.

Return Value

Type: void

setButtonLabel(fieldId, label)

Set the label of a button added to the preference form.

Signature

public void setButtonLabel(String fieldId, String label)

Parameters

fieldId
Type: String
Identifies a field in the preference form.
label
Type: String
The label for a button added to the preference form.

Return Value

Type: void

setOptions(fieldId, options)

Add a list of selectable options for a field on a preference form.

Signature

public void setOptions(String fieldId, List<System.SelectOption> options)

Parameters

fieldId
Type: String
Identifies a field in the preference form.
options
Type: List<System.SelectOption>
The selectable options for a field in the preference form.

Return Value

Type: void

setSelectedOption(fieldId, optionValue)

For a picklist or radio button field on a preference form that has defined values, set the value entered in the optionValue field as the selected option.

Signature

public void setSelectedOption(String fieldId, String optionValue)

Parameters

fieldId
Type: String
Identifies a field in the preference form.
optionValue
Type: String
The value for the selected option.

Return Value

Type: void

setSelectedOptions(fieldId, options)

For an existing checkbox field on a preference form that has defined values, set the values entered in the options field as the selected options. This requires the field on the form to have defined options with a set value.

Signature

public void setSelectedOptions(String fieldId, List<String> options)

Parameters

fieldId
Type: String
Identifies the checkbox field in the preference form.
options
Type: List<String>
The selected options for a field in the preference form.

Return Value

Type: void

setTextHint(fieldId, hintText)

Set the hint text inside a text input field. The hint text tells the user what type of information to enter, like an email address.

Signature

public void setTextHint(String fieldId, String hintText)

Parameters

fieldId
Type: String
The ID of the text input field in the preference form.
hintText
Type: String
The hint text in the text input field.

Return Value

Type: void

setTextValue(fieldId, value)

Set the value of a text field in a preference form.

Signature

public void setTextValue(String fieldId, String value)

Parameters

fieldId
Type: String
Identifies a field in the preference form.
value
Type: String
Represents the value entered for the text field in a preference form.

Return Value

Type: void