I need to load the attribute information about a Workflow rule into a custom object. I need the description, criteria, evaluation rule, and anything other detail about the workflow rule. Does anyone have code?

2 Answers 2


Look at Andrew Fawcett's Apex wrapper for the Metadata API. Code on GitHub, how-to on his blog.

  • Thanks for the plug Thomas! Retrieving Metadata is about to become a lot simpler with Spring'14's new 'retrieve' operation, update blog out soon once the rollout completes! Feb 18, 2014 at 0:04
  • I have looked at this several times. I am missing something. I am seeing how to get fullName, but I need the other attributes. I am trying to map the info.
    – user6905
    Feb 18, 2014 at 2:34

I figured I post the code I am trying to use and maybe you can point me in the right direction:

This is the line I am erroring on - mapWorkFlowEntity.put(fileProperty.fullName, fileProperty );

    MetadataService.MetadataPort service = createService();  
    List<MetadataService.ListMetadataQuery> queries = new List<MetadataService.ListMetadataQuery>();        
    MetadataService.ListMetadataQuery queryWorkflow = new MetadataService.ListMetadataQuery();
    queryWorkflow.type_x = 'WorkflowRule';

    MetadataService.FileProperties[] fileProperties = service.listMetadata(queries, 25);
        Map<String,MetadataService.FileProperties[]>  mapWorkFlowEntity = new Map <String,MetadataService.FileProperties[]> ();     
    for(MetadataService.FileProperties fileProperty : fileProperties){
        mapWorkFlowEntity.put(fileProperty.fullName, fileProperty );

    List<Workflow_Rules__c > newWR = new List<Workflow_Rules__c >();
    List<Workflow_Rules__c > existWR = new List<Workflow_Rules__c >();

    List<Workflow_Rules__c> WorkFlowList = [SELECT Id, Description__c, Evaluation_Criteria__c, If_email_specify_recepients__c, 
                                            If_email_template_used__c, If_field_update_what_field__c, 
                                            Is_this_a_time_based_workflow__c, Name, Rule_Criteria__c, Status__c, 
                                            What_actions_are_triggered__c, What_object_is_the_workflow_on__c FROM Workflow_Rules__c 
                                            Where What_object_is_the_workflow_on__c IN: ObjectIds];

    for(Workflow_Rules__c w:WorkFlowList){
            w.Description__c = mapWorkFlowEntity.get(w.Name).description;
            w.Evaluation_Criteria__c = mapWorkFlowEntity.get(w.Name).triggerType;
            w.If_email_specify_recepients__c = '';
            w.Is_this_a_time_based_workflow__c = mapWorkFlowEntity.get(w.Name).workflowTimeTriggers;
            w.Rule_Criteria__c = mapWorkFlowEntity.get(w.Name).formula;
            w.Status__c = mapWorkFlowEntity.get(w.Name).active;
            w.What_actions_are_triggered__c = mapWorkFlowEntity.get(w.Name).triggerType;
            w.What_object_is_the_workflow_on__c = '';
  • Don't update the question as an answer; edit the question and add in the additional details.
    – sfdcfox
    Feb 18, 2014 at 3:04

You must log in to answer this question.

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