The send2crm service 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 send2crm.FormValidator
interface.
global interface send2crm.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(send2crm.FormData data); }
Implementation classes should use global inherited sharing
, because form validation occurs during anonymous calls to public endpoints. The context user is that configured in the Salesforce Site.
The send2crm.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 send2crm.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 (send2crm__Validator__c
) picklist on the send2crm 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.