Input & Output

Validate an existing address

The validateAddress method is part of the Plauti Verify API, designed to validate and standardize address information. It checks the provided address against trusted external data sources and returns validation advice along with corrected or suggested addresses. This method works with the saveValidationResult method to store validation outcomes in Salesforce.

Method Signature

Method Name: validateAddress

global recordval.AddressValidationOutput_v1 validateAddress(recordval.AddressValidationInput_v1 addressInput)

Parameters

TypeVariableDescription
AddressValidationInput_v1addressInputThe structured input object containing address fields for validation.

Output

Return Type: AddressValidationOutput_v1

FieldTypeDescription
addressesList of Address_v1A list of suggested validated addresses.
adviceAdvice_v1Overall validation advice for the input (GREEN, AMBER, or RED). Use getAdvice() to retrieve as a string.
statusStatus_v1Provides detailed information about the validation process.

Save Validation Result

The saveValidationResult method allows developers to save the outcome of an address validation (status, status message, advice) directly to a Salesforce record, ensuring the results are easily accessible and tied to the appropriate record. For implementation details, see the saveValidationResult Class Reference

Apex Example

This snippet validates an address using the Record Validation API, logs the input, executes validation, and records status, suggestions, and geocodes if available.

// Initialize the Record Validation API
recordval.RecordValidationAPI_v1 api = new recordval.RecordValidationAPI_v1();
System.debug('Record Validation API initialized.');

// Optionally prepare AddressOptions to customize the validation request
recordval.AddressOptions_v1 addressOptions = new recordval.AddressOptions_v1();
addressOptions.housenumber = false; // Ensure house numbers are returned in a dedicated field
addressOptions.housenumberAddition = false; // Ensure house number additions are returned in a dedicated field
addressOptions.geocode = true; // If set to true, return geocodes (latitude and longitude)
addressOptions.addressSeparator = ','; // Specify the address separator format
System.debug('AddressOptions configured: ' + addressOptions);

// Prepare the address input
recordval.AddressValidationInput_v1 input = new recordval.AddressValidationInput_v1();
input.street     = 'Jansbuitensingel 6'; // Required field
input.country    = 'NL';   // Required field
input.city       = 'Arnhem';
input.state      = 'Gelderland';
input.postalcode = null;
input.note       = 'Validate Address via RV API';
input.addressOptions = addressOptions; // Attach AddressOptions to the input
System.debug('Address input prepared:');
System.debug('Street: ' + input.street);
System.debug('City: ' + input.city);
System.debug('State: ' + input.state);
System.debug('Postal Code: ' + input.postalcode);
System.debug('Country: ' + input.country);
System.debug('Note: ' + input.note);
System.debug('AddressOptions: ' + input.addressOptions);

// Execute the address validation
recordval.AddressValidationOutput_v1 output;
try {
    output = api.validateAddress(input);
    System.debug('Address validation executed successfully.');
} catch (Exception e) {
    System.debug('Address validation failed: ' + e.getMessage());
    return;
}

// Log the overall validation advice
System.debug('Validation Advice: ' + output.advice);

// Log the status details
if (output.status != null) {
    System.debug('Status Details:');
    System.debug('Status Code: ' + output.status.code);
    System.debug('Status Message: ' + output.status.message);
    System.debug('Credit Used: ' + output.status.credit);
} else {
    System.debug('No status information was returned.');
}

// Check for suggestions and log them
if (output.addresses != null && !output.addresses.isEmpty()) {
    System.debug('Validated Address Suggestions:');

    for (recordval.Address_v1 suggestedAddress : output.addresses) {
        System.debug('Suggested Street: ' + suggestedAddress.street);
        System.debug('Suggested City: ' + suggestedAddress.city);
        System.debug('Suggested State: ' + suggestedAddress.state);
        System.debug('Suggested Postal Code: ' + suggestedAddress.postalCode);
        System.debug('Suggested Country: ' + suggestedAddress.country);
        
        // Log the advice for each suggestion if available
        if (suggestedAddress.advice != null) {
            System.debug('Advice for Suggested Address: ' + suggestedAddress.advice);
        }

        // Log geocode information if available
        if (suggestedAddress.latitude != null && suggestedAddress.longitude != null) {
            System.debug('Latitude: ' + suggestedAddress.latitude);
            System.debug('Longitude: ' + suggestedAddress.longitude);
        }
    }
} else {
    System.debug('No validated address suggestions were returned.');
}