3

Is there any way to find out if a field is used in Workflow or not. I tried working with Metadata API's listMetadata call which returned me file properties . But no information about Field referenced in it.

Is there any other way to know field referenced in WF rule or validation rule ? listMetadata call Response for WF on ACCount

2

There isn't an API that tells you specifically where a field or object is used. You would need to download all the organization's metadata, then scan the contents for any reference to the field.

1

You can search for the fields (basically string) in the validation or the workflow rule. TO do this we can use the new tooling object that have been exposed as part of the new spring '14 release, ValidationRule and WorkflowRule object. You can run the below code in the developer console and in the debug you will find the validation's formula which is basically a string. Since the returned response it JSON format, you can deserialize the response and easily search thru the result for the field.

String salesforceHost = System.Url.getSalesforceBaseURL().toExternalForm();

String url =  salesforceHost + '/services/data/v30.0/tooling/query/?q=Select+fullname+,metadata+from+ValidationRule';

HttpRequest req = new HttpRequest();

req.setMethod('GET');
req.setEndpoint(url);
req.setHeader('Content-type', 'application/json');
req.setHeader('Authorization', 'Bearer ' + UserInfo.getSessionId());
Http http = new Http();

HTTPResponse res = http.send(req);
System.debug(res.getBody());

The metadata field is not of primitive type, but of type ValidationRuleMetadata which has a field errorConditionFormula which will have the validation formula which you can use to do a string search and find the field. Similarly you can query the WorkflowRule object.

  • this response for the HTTP call was "message: Select fullname ,metadata from ValidationRule^ ERROR at Row:1:Column:32 sObject type 'ValidationRule' is not supported. If you are attempting to use a custom object, be sure to append the '__c' after the entity name. Please reference your WSDL or the describe call for the appropriate names." Is it because of API version ? – Soberano Feb 27 '14 at 10:03
  • yes,You may be getting this error as you might have entered v29.0 in the URL instead of version 30. I had a run the above code in a sandbox which has been upgraded to spring'14. But when I run it in my developer instance which is still in winter'14, I get a error which says The requested resource does not exist. So probably we will have to wait till the spring'14 patch has been applied to our instances – Sam Feb 27 '14 at 11:49
0

I have created a python script that can find string (name of components) in directory and all sub-directories. You can use it to find list of component names in all metadata downloaded.

Usage:

python references.py <Directory to search> <Comma Separated List of components to search> [> result_report.csv]

Example to search fields among all metadata:

python references.py src/ Years_Employed__c,Years_Married__c,Age__c,Anniversary_Date__c,Testimonials__c > occurences.csv

Python Code:

import os
import sys

rootdir = sys.argv[1]

csvValues = sys.argv[2]

for str2Find in csvValues.split(','):
    occurences = []
    for dirname, subFolders, files in os.walk(rootdir):
        for filename in files:
            filepath = os.path.join(dirname, filename)
            lineNum = 0
            for fileLine in open(filepath, 'r'):
                if str2Find in fileLine:
                    occurences.append(filepath + ':' + str(lineNum) + ':' + fileLine.replace('"','""'))
                lineNum += 1
    if occurences:
        print '"' + str2Find + '","' + ''.join(occurences).strip() + '"\r\n',
    else:
        print '"' + str2Find + '",""\r\n',
0

Pretty old thread but adding another option. I have a free and open source app that scans the fields in your Org and returns the components it's used in (Workflows, Processes, Page Layouts, Apex etc).

Keep in mind that returning fields in Apex and VF is not 100% accurate, as a field with the same API name on different objects would return as being found in a class, even though it might not.

Keep it mind it can also take quite a while to run on large Orgs.

App: http://schemalister.herokuapp.com/

Source Code: https://github.com/benedwards44/schemalister

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.