S4S Cloud provides a mechanism to add custom form validation that runs in Salesforce prior to processing form submissions.
Apex class
Create an Apex class that implements the FuseIT_S4SCloud.FormValidator
interface.
global interface FuseIT_S4SCloud.FormValidator { /** * Determine whether form data is valid and should be processed. * @param data The parsed form object with field values. * @return True if the form should be processed, false to cancel. */ Boolean isValid(FuseIT_S4SCloud.FormData data); }
Implementations should use inherited sharing
, because form validation occurs during anonymous calls to public endpoints. The context user is that configured in the Salesforce Site.
The FuseIT_S4SCloud.FormData
object contains the form field values submitted from the website. Access these values using the following method. The return value will be of the appropriate type if found, or null if not found.
global with sharing class FuseIT_S4SCloud.FormData extends JsonData { /** * Get a single field value. * @param fieldName The field name/key excluding the standard prefix. * @return The field value if found, otherwise null. */ global Object getFieldValue(String fieldName); }
Mapping picklist
To use the validation for a form mapping, it needs to be available in the Validator (FuseIT_S4SCloud__Validator__c
) picklist on the S4S Cloud Mapping object. The API name must be the exact name of your validation class, including namespace if applicable.
Configure each relevant form mapping to use the validator.