saveValidationResult
The saveValidationResult
method stores the validation results for a specific record in Salesforce.
Class Summary
The saveValidationResult
method stores the validation results for a specific record in Salesforce. It takes an input object containing the record ID and the validation output, saving the validation feedback (e.g., status, advice, or suggestions) for future reference or auditing. This method is typically used after validating an address, email, or phone number to persist the results tied to the record.
Method Signature
Method name: saveValidationResult
global rv2SaveValidationResultOutput_v1 saveValidationResult(
rv2SaveValidationResultInput_v1 saveValidationRequest
)
Parameters
Field Name | Type | Description |
---|---|---|
saveValidationRequest | rv2SaveValidationResultInput_v1 | The input object containing the record ID, field name, and validation result. |
Output
The saveValidationResult
method returns an instance of the rv2SaveValidationResultOutput_v1 class.
Apex Example
This snippet validates the address of a Lead record in Salesforce and saves the validation result. It initializes the Record Validation API, prepares the address input, and executes validation. If validation is successful, it stores the result using saveValidationResult
. It logs relevant details, including validation advice, status, and success or failure messages.
// Initialize the Record Validation API
recordval.RecordValidationAPI_v1 api = new recordval.RecordValidationAPI_v1();
System.debug('Record Validation API initialized.');
// Define the record ID for a Lead
Id leadId = '00Q5g00000B12345'; // Replace with a valid Lead ID
System.debug('Lead ID: ' + leadId);
// Create validation input
recordval.AddressValidationInput_v1 input = new recordval.AddressValidationInput_v1();
input.street = '123 Main Street';
input.city = 'Springfield';
input.state = 'IL';
input.postalcode = '62701';
input.country = 'US';
System.debug('Validation input prepared: ' + input);
// Execute address validation
recordval.AddressValidationOutput_v1 output;
try {
output = api.validateAddress(input);
System.debug('Validation executed successfully. Advice: ' + output.advice);
} catch (Exception e) {
System.debug('Validation failed: ' + e.getMessage());
return;
}
// Check if there are validation results to save
if (output != null) {
// Prepare the validation result input
recordval.rv2SaveValidationResultInput_v1 saveRequest = new recordval.rv2SaveValidationResultInput_v1();
saveRequest.setRecordId(leadId);
saveRequest.setValidationResult('Street', output);
// Save the validation result
recordval.rv2SaveValidationResultOutput_v1 saveResult;
try {
saveResult = api.saveValidationResult(saveRequest);
if (saveResult.success) {
System.debug('Validation result saved successfully for record ID: ' + saveResult.recordId);
} else {
System.debug('Validation result save failed.');
}
} catch (Exception e) {
System.debug('Error saving validation result: ' + e.getMessage());
}
} else {
System.debug('No validation result to save.');
}
Updated about 1 month ago