Activity Forums Salesforce® Discussions How to Search Workflow Rules or Validation Rules etc in Apex i.e. Metadata Search via Apex?

  • How to Search Workflow Rules or Validation Rules etc in Apex i.e. Metadata Search via Apex?

    Posted by Deepak on October 7, 2019 at 11:11 am

    How to Search Workflow Rules or Validation Rules etc in Apex i.e. Metadata Search via Apex?

    Laveena replied 4 years, 6 months ago 2 Members · 1 Reply
  • 1 Reply
  • Laveena

    Member
    October 7, 2019 at 12:41 pm

    Hi Deepak,

    UPDATE: 11th Nov, I discovered the WorkflowRule (as apposed to the Workflow) metadata type! Combined with the ValidationRule metadata type. This means that the Metadata listMetadata API call now returns exactly the two lists you need to implement your search tool.

    This will allow you to list the Validation Rules and Workflow Rules from Apex.

    MetadataService.MetadataPort service = MetadataServiceExamples.createService();
    List<MetadataService.ListMetadataQuery> queries = new List<MetadataService.ListMetadataQuery>();
    MetadataService.ListMetadataQuery queryWorkflow = new MetadataService.ListMetadataQuery();
    queryWorkflow.type_x = 'WorkflowRule';
    queries.add(queryWorkflow);
    MetadataService.ListMetadataQuery queryValidationRule = new MetadataService.ListMetadataQuery();
    queryValidationRule.type_x = 'ValidationRule';
    queries.add(queryValidationRule);
    MetadataService.FileProperties[] fileProperties = service.listMetadata(queries, 25);
    for(MetadataService.FileProperties fileProperty : fileProperties)
    System.debug(fileProperty.fullName);

    Thanks

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos