After adding a new validation rule, existing records may be 'invalid'. This causes issues for me because processes and batches will fail to update those records.
How can I identify which records are invalid? perhaps by some sort of batch operation?
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It only takes a minute to sign up.Sign up to join this community
The safest way is to query for records that would cause the Validation Rule to fire and run a Data Loader update to fix only those records. You should be able to write a SOQL query for just about any Validation Rule (other than those using, e.g.,
PRIORVALUE(), which I don't think is the area of concern here) to identify records that would fail the rule on an otherwise-innocuous.
I'd suggest executing that query through the Data Loader's query module or Workbench in 'Bulk CSV' mode to avoid time-out issues and ensure you have access to the data for correction.
For example, if your Validation Rule were
AND(ISPICKVAL(Industry, "Finance"), ISBLANK(BillingStreet))
you could query
SELECT Id FROM Account WHERE Industry = 'Finance' AND BillingStreet = null
and then work to remediate those Accounts.
There's another approach involving performing a global update operation with the Data Loader and finding the "bad" records in your error file. It's a lot less safe and can have negative consequences depending on how your org is customized and whether your automations have side effects, so I really don't recommend it.
I'll elaborate a bit. Let's suppose you're working with Leads, and you want to do your global update on Lead to find the bad records. There's three areas where I've seen negative side effects:
A simpler way to do this would be to use dataloader. For example, let's say you made a bunch of new validation rules on Account (any sObject, follow same pattern) and want to identify existing records that are now "invalid" and un-editable, due to the new validation rules. Follow these steps to easily identify this subset of records.
1. Perform export via Dataloader. Simply export the ID column, nothing else is needed.
2. Perform Update via Dataloader. Simply match ID to ID.
3. Observe the failed updates in the "errors" CSV that is automatically generated. Read the error message to identify the cause behind the failure. Should be easy to pinpoint the records that failed due to your new validation rules.