function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Avinash AAvinash A 

Get Workflow Rule details

Hi, I am trying to get all workflow rules and its status(Active or not).I am able to get only Workflow name.Need help......
Prashant Pandey07Prashant Pandey07

Avinash,

How are you trying to retrieve the workflow rule and status..if you will create a workflow list view you can get all status and description of all workflow rule..

You can also use tool api to query the workflow rule...Go to workbech and select REST Explore and execute below url.
/services/data/v41.0/tooling/query?q=Select+Id,Name,TableEnumOrId+From+WorkflowRule


--
Thanks,
Prashant
Musunuru SurekhaMusunuru Surekha
Hi Avinash,

You can create a new view and in filter criteria,specify Active equals TRUE. Let me know if this helps
Avinash AAvinash A
Hi  @Prashant Pandey07 ,

I am trying to get workflow information in apex code. but i am not able to get status(Active or not) in the apex code.
Avinash AAvinash A
Hi  @Prashant Pandey07 ,

Is there any way to access to workflow rules from SOQL query 
Prashant Pandey07Prashant Pandey07
You need to use tooling API if you want to query the workflow rule..
Check this sample code that may help you to get the status of an individual workflow.

Set the endpoint as your org URL in remote site setting and execute this code in developer console you will see all the attributes of workflow rule..
 
Public class DemoforToolingApi
{
public String returnValuestr ;
public HttpResponse response;
public Http http;
public HttpRequest request;
public DemoforToolingApi ()
{
returnValuestr = httpCalloutMethod('/services/data/v41.0/tooling/sobjects/WorkflowRule/{ID}');
System.debug('returnValuestr –> '+returnValuestr );
}

public String sToken=UserInfo.getSessionId();
public String httpCalloutMethod(String str)
{
try
{
http = new Http();
request = new HttpRequest();
String getORGURL=URL.getSalesforceBaseUrl().toExternalForm();

request.setEndpoint(getORGURL+str);  //Your URI
request.setMethod('GET');
request.setHeader('Authorization', 'Bearer ' + sToken);
//if the request and response for your REST call is JSON, use the code below.
request.setHeader('Content-Type', 'application/json');
request.setHeader('accept', 'application/json');
response = http.send(request);
return response.getBody();
}
catch(Exception e) {
System.debug('Error —-> '+e);
return null;

}
}
}


 
Avinash AAvinash A
Hi  @Prashant Pandey07 ,

In the above example you are passing ID.Is it workflow rule ID.
If yes , It can only get one work flow details ryt?

My requirement is to get all WorkFlowRules in the org.
If you have some work arounds , Please Let me know.
Prashant Pandey07Prashant Pandey07
Hi Avinash,

If you don't want to get the details of specific workflow then just remove the id and give a try.


--
Thanks,
Prashant