How to enable validations to save, update, and delete records
Learn how to use validations to confirm data updates, ensuring accuracy and success in data management.
Introduction
The validation callback feature is a Salesforce Hypergrid Extended Related List component that allows you ( Power User) to specify a JavaScript function that is called whenever any user attempts to update field values in specific columns or delete records. This functionality allows the update and deletes operation to be successful only when the conditions specified in the code are met. Thus, through validations, conditional update and delete is enabled.
As an argument, the new row data is passed to this function, which can perform any custom validation or modification of the data before it is saved. If the function returns a false value, the save operation is aborted and the user is shown an error message. You can use this to enforce custom business rules or validate user input before saving it to the database.
In this article, we will understand how to:
- Edit/ Update “Before save validation callback” JS component
- Edit/ Update “Before delete validation callback” JS component
- Determine the chunk size for save and delete actions
Which type of user can use this functionality?
HyperGrid XRL Power users have the right to edit the JavaScript code to enable the validation callback function in case of bulk edit and bulk delete by accessing the Table Settings in the Configuration wizard.
Prerequisite The Power user must perform the configuration in order to customize the data. Refer to the links below for more detailed instructions. |
Before Save Validation Callback
"Before save validation callback" is a Salesforce HyperGrid Extended Related List feature that lets you define a JavaScript function that runs before a record is saved to the database. This function can be used to perform custom validation on a record and prevent it from being held if the validation fails. The validation function can access and modify record field values, as well as display error messages if necessary.
Procedure
We will work with the Cases XRL example to walk you through the steps.
Step 1: Click on the settings dropdown on the right and click on Configure option.
Step 2: The configuration wizard is displayed. Click on the Table Settings tab.
Step 3: In the Before Save Validation Callback field, enter the javascript code that you want to execute before the Save action. This function serves as a validation callback before saving data to a database. For example, in the given use case, it checks if the Case Origin column being saved is defined and has the value "Email". If it does, the function returns true, allowing the save to continue. If it does not, it returns false, and the edited value will not be saved.
Example Code to run “Before Save Validation”
function(record){
if(record.Origin !== undefined && record.Origin === 'Email'){
return true;
}else{
return false;
}
}
Step 4: Click Save to save the changes. Click Save As to save the changes under a new name.
Results
After enabling the validation callback functionality, any standard user attempting to edit fields where the Case Origin column is not Email will not be updated.
Before Delete Validation Callback
In the Salesforce HyperGrid Extended Related List, "Before delete validation callback" refers to a function that is called just before deleting a record from a related list displayed in a HyperGrid component. This function enables Power Users to define custom validations and conditions that must be met before deleting a record. If any validations fail, the deletion is prevented, and the user is notified of the error.
Procedure
We will work with the Cases example to walk you through the steps.
Step 1: Click on the settings dropdown on the right and click on Configure option.
Step 2: The configuration wizard is displayed. Click on the Table Settings tab.
Step 3: In the Before Delete Validation Callback field, enter the javascript code that you want to execute before the Delete action. This function serves as a validation callback before deleting data from the database. It checks to see if the data being deleted has the value “Email” in the Case Origin column. If it does, the function returns true, allowing the delete to continue. If it does not, it returns false, and the edited value will not be deleted from the database.
Example Code to run “Before Delete Validation”
function(record){
if(record.Origin !== undefined && record.Origin === 'Email'){
return true;
}else{
return false;
}
}
Step 4: Click Save to save the changes. Click Save As to save the changes under a new name.
Results
After enabling the validation to delete callback functionality, any standard user attempting to delete fields where the value of the Case Origin column is Email will be deleted from the database. Other fields where the values of the Case Origin column are Phone, and Web, will not be deleted from the database.
Determine the Chunk Size for Edit and Delete Actions
When multiple records in a Salesforce HyperGrid Extended Related List are changed, the chunk size for the save action and chunk size for delete actions functionalities determine how many records are saved or deleted in a single batch. HyperGrid XRL saves/deletes changes in batches of 200 records by default. Power users can, however, specify a custom number to optimize performance and ensure that all changes are properly saved/deleted. This is especially useful when changing a large number of records at once, as it can help prevent timeouts and increase overall productivity.
Procedure
We will work with the Cases example to walk you through the steps.
Step 1: Click on the settings dropdown on the right and click on Configure option.
Step 2: The configuration wizard is displayed. Click on the Table Settings tab.
Step 3: Enter the chunk size for save and delete actions as shown below. Click Save to save the configuration.