1

Is it possible to get below things using Apex:

  1. I want to get field Updates that are used in a particular or all WorkFlow rule/s.
  2. I want to get Workflow rules and approval Processes that are associated with a single WorkflowFieldUpdate.
3

Yes, it's possible. You can access Workflow Rule metadata through the Metadata API. There is an Apex wrapper available, and its README and examples class include some examples that can be adapted to get started on your objectives.

To read out Workflow Rule metadata, for example, you can do

MetadataService.MetadataPort service = new MetadataService.MetadataPort();
service.SessionHeader = new MetadataService.SessionHeader_element();
service.SessionHeader.sessionId = UserInfo.getSessionId();

List<MetadataService.ListMetadataQuery> queries = new List<MetadataService.ListMetadataQuery>();        
MetadataService.ListMetadataQuery queryWorkflow = new MetadataService.ListMetadataQuery();
queryWorkflow.type_x = 'WorkflowRule';
queries.add(queryWorkflow);     
MetadataService.FileProperties[] fileProperties = service.listMetadata(queries, 25);
for(MetadataService.FileProperties fileProperty : fileProperties) {
            MetadataService.WorkflowRule wfr =
            (MetadataService.WorkflowRule) service.readMetadata('WorkflowRule',
new String[] { fileProperty.fullName }).getRecords()[0];
            System.debug(wfr);
}

That's not very efficient but it'll output each Workflow Rule's XML metadata into your logs, and you can examine it as an aid to understanding the (quite complex) metadata.

To implement your actual requirements, you'll want to extract your Workflow Rules along the lines above and examine their properties. You can find a reference here, in the Metadata API reference. The actions property includes a list of WorkflowActionReference items you can inspect, looking for the type_x property to be FieldUpdate.

For Approval Processes, a similar sequence of operations would obtain. See ApprovalProcess in the Metadata API documentation for more, but you'd be looking at its several properties (finalApprovalActions and so on) that have the type ApprovalAction. That type has only one property, action, which is a list of WorkflowActionReference just like with Workflow Rules. You should be able to write the logic to correlate that data.

The Tooling API's WorkflowRule support is layered on top of the Metadata API's. You could certainly go that route but you'll have to do some of the additional work to walk through the very complex response body that is handled by the apex-mdapi wrapper for you.

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.