Loading
Salesforce Enforces New Security Requirements in Summer 2026Read More
Data Protection and Privacy
Create an Apex Class for Preference Manager

Create an Apex Class for Preference Manager

Use Preference Builder along with the Pref_center Apex namespace to create forms with advanced customizations. The Pref_center Apex namespace represents the former name of the Preference Manager feature.

Required Editions

Available in: Lightning Experience and Salesforce Classic in Developer, Enterprise, Performance, and Unlimited Editions
User Permissions Needed
To use Preference Manager: ManagePreferenceManager

When you create your form in Preference Builder, the details, like the names and configuration of sections that you included, are saved as metadata. When a user opens the preference form, your custom Apex class retrieves and sets that metadata to configure the form on your site. Then when the user completes and submits the form, the Apex class creates or updates the submitted data into the relevant Salesforce consent objects.

Before you configure the preference form, create your Apex class to control how data passed through the form is managed.

  1. From Setup, in the Quick Find box, enter Custom Code, select Apex Classes, and then click New.
  2. In the Apex Class text box, copy and paste this code, and replace [YOUR APEX CLASS NAME] with the name that you want for your Apex class:
Example
Example
public without sharing class [YOUR APEX CLASS NAME] implements pref_center.PreferenceCenterApexHandler {
public void submit(pref_center.SubmitParameters submitParams, pref_center.SubmitFormData formData, pref_center.ValidationResult validationResult) {

}

public pref_center.LoadFormData load(pref_center.LoadParameters loadParams, pref_center.LoadFormData loadFormData, pref_center.ValidationResult validationResult) {
return loadFormData;
}
}

For more information about Apex classes, see the Apex Developer Guide and the Create an Apex Class module in Trailhead.

 
Loading
Salesforce Help | Article