How to apply Record Validation to your Objects

Last published at: 2024-08-26 11:30:48 UTC
Delete

Do you want to use Record Validation for an Object (standard or custom) other than Lead, Contact or Account? Use this guide to configure Record Validation for your other Objects.

1. Add your Object to the Record Validation Setup

Navigate to the Record Validation Setup page. At the "Object Setup", click "Add Object" and find the Object you wish to configure. Record Validation can work with any Object in Salesforce.

2. Map your field sets for Address, Email and Phone

Navigate to the Address, Email and Phone tabs in the Record Validation Setup and map the fields you want to use with Record Validation.

3. Override your 'New' and 'Edit' button

Override the 'New' button. 

  1. Navigate to the Salesforce Setup.
  2. Navigate to Platform Tools - Objects and Fields - Object Manager.
  3. Find your (custom) Object in the list view and access it.
  4. Navigate to Buttons, Links and Actions.
  5. Find the 'New' button and click 'Edit'.
  6. At 'Lightning Experience Override', select 'Lightning Component'. 
  7. In the select list, pick 'recordval:recordForm'.
  8. Click Save.
    Override the 'Edit' button.
  9. Find the 'Edit' button and click 'Edit'.
  10. At 'Lightning Experience Override', select 'Lightning Component'.
  11. In the select list, pick 'recordval:recordForm'.
  12. Click Save.

4. Create all required custom fields

Create the custom field "RV Record Status"

  1. Navigate to Salesforce Setup. Navigate to the Object Manager.
  2. Find and Open your custom object. Click on "Field & Relationships"
  3. Click the "New" button.
  4. Step 1. Under Data Type choose "Picklist" and click Next.
  5. Step 2. Fill only the following information and then click Next:
    Field Label: RV Record Status
    Values: Click on the drop-down menu and select "RV Record Status" option.
    Field Name: rv2Status
  6. Step 3. Depending on your Salesforce edition (Professional and up), you will now get a screen to establish field-level security.  Click 'Next'. 
  7. Step 4. Depending on your Salesforce edition (Professional and up), you will now get a screen where you are able to add the field to the page layout. Since this is a background process, this should not be applied to any page layout. Uncheck any page layout and click Next.
  8. Now, after creating the "RV Record Status" field, you need to map it in the RV Setup. Navigate to RV Setup and click on the Custom Object
  9. Select the field from the drop-down menu under "Field Configuration". 

    Click here to watch a short video of how to do that

5. Create the custom field "RV Validation Result"

Create the custom field "RV Validation Result"

  1. Navigate to Salesforce Setup. Navigate to the Object Manager.
  2. Find and Open your custom object. Click on "Field & Relationships"
  3. Click the "New" button.
  4. Step 1. Under Data Type choose "Text Area(Long)" and click Next.
  5. Step 2. Fill the following information and then click Next.
    Field Label: RV Validation Result
    Field Name: rv2Validation
  6. Depending on your Salesforce edition (Professional and up), you will now get a screen to establish field-level security. Click 'Next'. 
  7. Step 4. Depending on your Salesforce edition (Professional and up), you will now get a screen where you are able to add the field to the page layout. Since this is a background process, this should not be applied to any page layout. Uncheck any page layout and click Next.
  8. Now, after creating the "RV Validation Result" field, you need to map it in the RV Setup. Navigate to RV Setup and click on the Custom Object
  9. Select the field from the drop-down menu under "Field Configuration". 

    Click here to watch a short video of how to do that.

6. Create the Apex Trigger (mandatory)

Delete

As per Salesforce policy, you first need to create the Apex Trigger in your sandbox and then deploy from sandbox to production

  1. Go to the Salesforce Setup > Object Manager.
  2. In the Object Manager, find the custom object you want to use and click on it. 
  3. Under Details, copy the API Name of the Object.
  4. At the left, go to the Triggers tab.
  5. At top right, click New.
  6. Replace all code in the box with the Apex Trigger code below. Make sure you replace *OBJECT_NAME* and *OBJECT_API_NAME* with the name and API name of your Custom Object.

    Click here to watch a short video of this step.

    trigger rv2**ObjectName** on **OBJECT_API** (after delete, after insert, after undelete, after update, before delete, before insert, before update) {
            if (!recordval.rv2Trigger.triggerSource.equalsIgnoreCase('SELF') || recordval.rv2TriggerMapper.isTriggerDisabled()) {         return;     }         recordval.rv2Trigger triggerProcess = recordval.rv2TriggerMapper.get('**OBJECT_API**', 'rv2Status__c', 'rv2Validation__c');     triggerProcess.execute(trigger.new, trigger.oldMap,trigger.isBefore, trigger.isAfter, trigger.isInsert, trigger.isUpdate, trigger.isDelete, trigger.isUndelete);     }
  7. Click Save

The trigger has been created.

Delete

As per Salesforce policy, you first need to create the Apex Trigger in your sandbox and then deploy from sandbox to production.


Delete

That's it! You have now configured Record Validation for your (custom) Object. You can now start validating your records. Check out our Usage Guide to find out more.