1

I've recently setup vs code in hopes that I could easily download all validation rules and search across them for a string. We're updating our roles and role names are used in a lot of validation rules. I'd much rather do a find and replace across our validation rules than go through each one in the UI.

I now know that validationrules are in a folder under the object. My questions are: 1) How do I download ALL objects, standard and custom, to search through. 2) Is there a way to narrow my search so it only searches within the ValidationRules folder for each object?

Thanks in advance.

2 Answers 2

0

An approach you can take is to use Workbench and the Tooling API to get a list of all the Validation Rule API Names in the org:

/services/data/v47.0/tooling/query?q=Select+EntityDefinitionId,ValidationName+From+ValidationRule

and then concatenate the EntityDefinitionId + '.' + ValidationName

You can then take the list of Validation Rule API names and construct a package.xml file similar to this:

<types>
        <members>StandardObject.ValidationRule__c</members>
        <members>CustomObject.ValidationRule__c</members>
...
        <name>ValidationRule</name>
</types>

You can then use the Force.com Migration Tool to download these Validation Rules and then use VSCode to perform a search through all the files downloaded

7
  • Okay, two questions. Is force.com migration tool the same thing as ANT? Also, if I have a package.xml containing all the validation rules, can't I just retrieve them via VS Code directly? I actually didn't know you could have just validation rule as a type, I thought you had to get the entire object. I will test this out.
    – jameskbw
    Commented Jan 16, 2020 at 14:29
  • @jameskbw Yes, more or less. The force.com migration tool is a library that enables ANT to use Salesforce's metadata API to deploy and such. I don't think VSCode can directly pull data from Salesforce, but SFDX can take a package.xml and retrieve the specified metadata (something like sfdx force:source:retrieve -x myPackage.xml). The ValidationRule metadata type is contained within the CustomObject metadata type. In source form, they'll appear as a sub-folder of "Objects".
    – Derek F
    Commented Jan 16, 2020 at 14:49
  • @DerekF - thanks for the info. Just to clarify, are you saying that if I use the force.com migration tool that I can somehow extract only the validation rules, or will I always have to get the custom object metadata with them?
    – jameskbw
    Commented Jan 16, 2020 at 14:55
  • 1
    @jameskbw I think that using ANT (shorter to type) might fetch a bare-bones object definition. I personally try to stay in source form and avoid the metadata api form (and the metadata api) though. Using SFDX, however, you can fetch just the validation rule.
    – Derek F
    Commented Jan 16, 2020 at 15:07
  • @DerekF I was able to fetch just the validation rule without custom object using your package suggestion. However, I can't figure out how to get all validation rules to put into the package easily. When I go to workbench and go to utilities > rest explorer and paste in the query you posted, I get an error: message: When retrieving results with Metadata or FullName fields, the query qualificatio​ns must specify no more than one row for retrieval. Result size: 195 errorCode: MALFORMED_QUERY Any ideas?
    – jameskbw
    Commented Jan 17, 2020 at 14:54
2

You need to edit your package.xml file.

To download all custom objects:

<types>
    <members>*</members>
    <name>CustomObject</name>
</types>

My understanding is that standard objects and managed package objects need to be defined specifically:

<types>
    <members>pse__Assignment__c</members>
    <name>CustomObject</name>
</types>

After you define all the objects you care about, you can do a search through only the validation folders by right clicking any folder and selecting "find in folder" Then replace the object name with a *:

./force-app/main/default/objects/*/validationRules
1
  • Appreciate the answer. I marked the other answer only because I'd prefer to extract the validation rule without the object metadata.
    – jameskbw
    Commented Jan 17, 2020 at 15:25

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .