> For the complete documentation index, see [llms.txt](https://docs.work-relay.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.work-relay.com/automations/api/api-methods.md).

# API methods

## ChatterService

<details>

<summary>postFeed</summary>

Posts feed to object chatter.

**Usage:**

{% code overflow="wrap" %}

```apex
postFeed(List<ID> parents, String message, String url (optional),List<String> topics (optional),List<ID> mentions (optional))
```

{% endcode %}

**Return Value**: none

**Example:**

{% code overflow="wrap" %}

```apex
new WR_BPM.API().call('ChatterService', 'postFeed', new Map<String, Object>{
    'parents' =>  array of users/objects ids
    'message' => feed body
    'url' =>  url that will be added to the body
    'topics' =>  array of topics titles
    'mentions' =>  array of users ids that will be mentioned in the feed
});
```

{% endcode %}

</details>

<details>

<summary>postComment</summary>

Posts comment to the specified feed.

**Usage:**

{% code overflow="wrap" %}

```apex
postComment(ID feedId, String message)
```

{% endcode %}

**Return Value:** none

**Example:**

{% code overflow="wrap" %}

```apex
new WR_BPM.API().call('ChatterService', 'postComment', newMap<String, Object>{
    'feedId' =>  id of chatter feed,
    'message' => comment body
});
```

{% endcode %}

{% hint style="info" %}
See related article: [Chatter API Methods](/functional/chatter-feeds/chatter-api-methods.md).
{% endhint %}

</details>

<details>

<summary>setDisabled</summary>

Disables posting feeds to any (task, process and object) chatter.

**Usage:**

{% code overflow="wrap" %}

```apex
setDisabled(Boolean Value)
```

{% endcode %}

**Return Value**: none

{% hint style="info" %}

* This method is used in Process Step Actions to temporary disable posting. This action does the same as "Enable Chatter Notifications" and "Enable Object Notifications" step properties set to "Yes", but can be executed with conditions (in comparison with properties above, that are executed always).
* This method when executed disables posting in one request only. Other steps posts will not be affected by it.
  {% endhint %}

{% hint style="success" icon="lightbulb-exclamation" %}

* If execute this action with Start Type = Before Step, a feed notifications will be disabled for that step. If set Start Type = After Step, this action will disable notifications about the subsequent step.
* Note, that subsequent step posts can still be made from other preceding step that has no such action set.
  {% endhint %}

**Example:**

{% code overflow="wrap" %}

```apex
new WR_BPM.API().call('ChatterService', 'setDisabled', true|false);
```

{% endcode %}

![](/files/9e7194e2f73d249c6d50370686aa2867a06609ca)

</details>

## EmailMessageService

<details>

<summary>sendEmailAlert</summary>

Sends email alert.

**Usage:**

{% code overflow="wrap" %}

```apex
sendEmailAlert(String alertType, List<String>toList, String subject, String body)
```

{% endcode %}

**Return Value:** none

**Example:**

{% code overflow="wrap" %}

```apex
new WR_BPM.API().call('EmailMessageService', 'sendEmailAlert', new Map<String, Object>{
    'alertType' => 'Generic Notification',
    'toList' => new List<String>{'email@test.com'}, // list of email addresses
    'subject' => 'subject',
    'body' => 'body'
});
```

{% endcode %}

</details>

<details>

<summary>sendEmailMessage</summary>

Sends email with attachments.

**Usage:**

{% code overflow="wrap" %}

```apex
sendEmailMessage(List<String>to, String subject, String body, String fromName, Boolean plainText, List<Attachment>attachments)
```

{% endcode %}

**Return Value:** none

**Example:**

{% code overflow="wrap" %}

```apex
new WR_BPM.API().call('EmailMessageService', 'sendEmailMessage', new Map<String, Object>{
    'to' => new List<String>{'email@test.com'}, // list of email addresses
    'subject' => 'subject',
    'body' => 'body',
    'fromName' => 'fromName', // value that will be displayed as the sender's name
    'plainText' => true/false,
    'attachments' => new List<Attachment>()
 });
```

{% endcode %}

</details>

<details>

<summary>sendEmailMessageByTemplate</summary>

Sends email using Salesforce email template.

**Usage:**

{% code overflow="wrap" %}

```apex
sendEmailMessageByTemplate(List<String>to, ID templateId, ID recordId, String fromName)
```

{% endcode %}

**Return Value:** none

**Example:**

{% code overflow="wrap" %}

```apex
new WR_BPM.API().call('EmailMessageService', 'sendEmailMessageByTemplate', new Map<String, Object>{
    'to' => newList<String>{'email@test.com'}, // list of email addresses
    'templateId' => 'SalesForce email template Id',
    'recordId' => 'template source record Id',
    'fromName' => 'fromName' // value that will be displayed as the sender's name
});
```

{% endcode %}

{% hint style="info" %}
sendEmailMessageByTemplate API will only work when Email Delivery Contact is set on Work Relay Settings:
{% endhint %}

![](/files/ea165886c84f17b84742c7ee0afdbd20640509e2)

</details>

## ConfigService

<details>

<summary>getDateFormat</summary>

Returns date format from Work-Relay config settings.

**Usage:**

{% code overflow="wrap" %}

```apex
getDateFormat();
```

{% endcode %}

**Return Value:** Object

**Example:**

{% code overflow="wrap" %}

```apex
new WR_BPM.API().call('ConfigService', 'getDateFormat', null);
```

{% endcode %}

</details>

<details>

<summary>getDateTimeFormat</summary>

Returns dateTime format from Work-Relay config settings.

**Usage:**

{% code overflow="wrap" %}

```apex
getDateTimeFormat();
```

{% endcode %}

**Return Value:** Object

**Example:**

{% code overflow="wrap" %}

```apex
new WR_BPM.API().call('ConfigService', 'getDateTimeFormat', null);
```

{% endcode %}

</details>

<details>

<summary>getNamespace</summary>

Returns Namespace from Work-Relay config settings.

**Usage:**

{% code overflow="wrap" %}

```apex
getNamespace();
```

{% endcode %}

**Return Value:** Object

**Example:**

{% code overflow="wrap" %}

```apex
new WR_BPM.API().call('ConfigService', 'getNamespace', null);
```

{% endcode %}

</details>

## GlobalActionService

<details>

<summary>executeAction</summary>

Executes the specified global action.

**Usage:**

{% code overflow="wrap" %}

```apex
executeAction(ID actionId, String source (optional), Map<String, Object> variables (optional))
```

{% endcode %}

**Return Value**: Object (Global Action Context)

**Example:**

{% code overflow="wrap" %}

```apex
new WR_BPM.API().call('GlobalActionService', 'executeAction', new Map<String, Object>{
    'actionId' =>  'global action ID', 
    'source' => 'global action source record ID',  //required if option has a source object
    'variables' => new Map<String, Object>{'variable_name' => 'variable_value'}
});
```

{% endcode %}

</details>

<details>

<summary>executeActionGroup</summary>

Executes the global action group.

**Usage:**

{% code overflow="wrap" %}

```apex
executeActionGroup(ID groupId, String source (optional), Map<String, Object> variables (optional))
```

{% endcode %}

**Return Value:** Object (Global Action Context)

**Example:**

{% code overflow="wrap" %}

```apex
new WR_BPM.API().call('GlobalActionService', 'executeActionGroup', new Map<String, Object>{
    'groupId' => 'global action group id',
    'source' => 'global action group source object', //required if global action group has a source object
    'variables' => new Map<String, Object>{'variable_name' => 'variable_value'}
});
```

{% endcode %}

</details>

<details>

<summary>executeInBatch</summary>

Starts a Salesforce batch job and executes the global action for each record.

**Usage:**

{% code overflow="wrap" %}

```apex
executeInBatch(String query, ID actionOrGroupId, IDfinishActionOrGroupId(optional), Boolean passSource (optional), Map<String, Object> variables (optional), Integer batchSize (optional), Boolean inSingleCall (optional))
```

{% endcode %}

**Return value:** Id (Apex Job Id)

**Example:**

{% code overflow="wrap" lineNumbers="true" %}

```apex
new WR_BPM.API().call('GlobalActionService', 'executeInBatch', new Map<String, Object>{
    'query' =>  query to get records, // e.g. 'select id from account limit 5'
    'actionOrGroupId' => ID of the action or action group,
    'finishActionOrGroupId' => ID of the action or action group that will be executed in the end of the batch,
    'passSource' =>  true/false //if "true" the current record will be passed to the action/group as the source object, otherwise current record id will be available in the action as {$Variables.recordId},
    'variables' => new Map<String, Object>{'variable_name' => 'variable_value'},
    'batchSize' =>  size of batch iteration,
    'inSingleCall' => true/false //if "true" executes action once for loaded records - this way records ids will be available in {$Environment.ids}
});
```

{% endcode %}

</details>

<details>

<summary>executeInScheduler</summary>

Initiates a Salesforce scheduled job and executes the global action.

**Usage:**

{% code overflow="wrap" %}

```apex
executeInScheduler(String name,String cron, String query, ID actionOrGroupId, String source (optional), Map<String, Object> variables (optional))
```

{% endcode %}

**Return Value:** Id (Apex Job Id)

**Example:**

{% code overflow="wrap" %}

```apex
new WR_BPM.API().call('GlobalActionService', 'executeInScheduler, new Map<String, Object>{
    'name' =>The name of the scheduled job,
    'cron' =>The CRON configuration for the scheduled job,
    'actionOrGroupId' => The ID of the action or action group,
    'source' => The ID of the source record,
    'variables' => new Map<String, Object>{'variable_name' => 'variable_value'}
});
```

{% endcode %}

</details>

## WorkflowActivator

<details>

<summary>startWorfkflow</summary>

Starts the specified process version by flow ID.

**Usage:**

{% code overflow="wrap" %}

```apex
startWorkflow(String flowId, String recordId, Map<String, Object> variables (optional))
```

{% endcode %}

**Return Value:** List\<Flow\_Instance\_\_c>

**Example:**

{% code overflow="wrap" %}

```apex
new WR_BPM.API().call('WorkflowActivator', 'startWorkflow', new Map<String, Object>{
  'flowId' => process version id
  'recordId' => process context object id
  'variables' => new Map<String, Object>{'variable_name' => 'variable_value'} // initial variables
});
```

{% endcode %}

</details>

<details>

<summary>startWorkflowByFlowName</summary>

Starts the specified process version by version name.

**Usage:**

{% code overflow="wrap" %}

```apex
startWorkflowByFlowName(String flowName, String recordId, Map<String, Object> variables (optional))
```

{% endcode %}

**Return Value:** List\<Flow\_Instance\_\_c>

**Example:**

{% code overflow="wrap" %}

```apex
new WR_BPM.API().call('WorkflowActivator', 'startWorkflowByFlowName', new Map<String, Object>{
  'flowName' => process version name,
  'recordId' => process context version id,
  'variables' => new Map<String, Object>{'variable_name' => 'variable_value'}
});
```

{% endcode %}

</details>

<details>

<summary>startWorkflowByProcessName</summary>

Starts the primary version of a process by process name.

**Usage:**

{% code overflow="wrap" %}

```apex
startWorkflowByProcessName(String processName, String recordId, Map<String, Object> variables (optional))
```

{% endcode %}

**Return Value:** List\<Flow\_Instance\_\_c>

**Example:**

{% code overflow="wrap" %}

```apex
new WR_BPM.API().call('WorkflowActivator', 'startWorkflowByProcessName', new Map<String, Object>{
  'processName' => The process name,
  'recordId' => SObject.Id,
  'variables' => new Map<String, Object>{'variable_name' => 'variable_value'}
});
```

{% endcode %}

</details>

<details>

<summary>setDisabled</summary>

Disables process-start logic for one request.

**Usage:**

{% code overflow="wrap" %}

```apex
setDisabled(Boolean value)
```

{% endcode %}

**Return Value:** none

**Example:**

{% code overflow="wrap" %}

```apex
new WR_BPM.API().call('WorkflowActivator', 'setDisabled', true|false);
```

{% endcode %}

</details>

<details>

<summary>setIgnoreFLows</summary>

Defines flows ignored by process-start logic. Works within one request.

**Usage:**

{% code overflow="wrap" %}

```apex
setIgnoreFlows(String value)
```

{% endcode %}

**Return Value:** none

**Example:**

{% code overflow="wrap" %}

```apex
new WR_BPM.API().call('WorkflowActivator', 'setIgnoreFlows', '["flowId_1", "flowId_2",....]');
```

{% endcode %}

</details>

<details>

<summary>setIgnoreRecords</summary>

Defines SObject records ignored by process-start logic. Works within one request.

**Usage:**

{% code overflow="wrap" %}

```apex
setIgnoreRecords(String value)
```

{% endcode %}

**Return Value:** none

**Example:**

{% code overflow="wrap" %}

```apex
new WR_BPM.API().call('WorkflowActivator', 'setIgnoreRecords', '["recordId_1", "recordId_2", ....]');
```

{% endcode %}

</details>

<details>

<summary>setCheckOnlyFlows</summary>

Defines flows checked by process-start logic. Other flows are ignored. Works within one request.

**Usage:**

{% code overflow="wrap" %}

```apex
setCheckOnlyFlows(String value)
```

{% endcode %}

**Return Value**: none

**Example:**

{% code overflow="wrap" %}

```apex
new WR_BPM.API().call('WorkflowActivator', 'setCheckOnlyFlows', '["flowId_1", "flowId_2", ....]');
```

{% endcode %}

</details>

<details>

<summary>setNewInstancesLimit</summary>

Sets the maximum process instances that can start for the current request.

**Usage:**

{% code overflow="wrap" %}

```apex
setNewInstancesLimit(String value)
```

{% endcode %}

**Return Value:** none

**Example:**

{% code overflow="wrap" %}

```apex
new WR_BPM.API().call('WorkflowActivator', 'setNewInstancesLimit', 10);
```

{% endcode %}

</details>

## WorkflowProceedService

<details>

<summary>completeStep</summary>

Proceeds a process step. Throws `WR_BPM.LimitsException` when a new transaction is required.

**Usage:**

{% code overflow="wrap" %}

```apex
completeStep(String cursorId, String operation, String comments (optional), Date startDate (optional), Date completeDate (optional), Map<String,Object> environment(optional))
```

{% endcode %}

**Return Value:** Boolean //if proceed executed successfully

**Example:**

{% code overflow="wrap" %}

```apex
new WR_BPM.API().call('WorkflowProceedService', 'completeStep', new Map<String, Object>{
  'cursorId' => Flow_Instance_Cursor__c.Id,
  'operation' => 'Proceed|Approve|Reject',
  'comments' => 'Some Comment',
  'startDate' => Actual Start DateTime,
  'completeDate' => Actual End DateTime, 
  'environment' => new Map<String,Object>{'name' => 'value'} //values that can be used via process {$Environment} while step proceeding
});
```

{% endcode %}

</details>

<details>

<summary>completeStep</summary>

Proceeds a process step. Throws `WR_BPM.LimitsException` when a new transaction is required.

**Usage:**

{% code overflow="wrap" %}

```apex
completeStep(Flow_Instance_Cursor__c flowInstanceCursor, String operation, String comments (optional), Date startDate (optional), Date completeDate (optional))
```

{% endcode %}

**Return Value:** Boolean //if proceed executed successfully

**Example:**

{% code overflow="wrap" %}

```apex
new WR_BPM.API().call('WorkflowProceedService', 'completeStep', new Map<String, Object>{
  'flowInstanceCursor' => Flow_Instance_Cursor__c,
  'operation' => 'Proceed|Approve|Reject',
  'comments' => 'Some Comment', 
  'startDate' => Actual Start DateTime, 
  'completeDate' => Actual End DateTime, 
  'environment' => new Map<String,Object>{'name' => 'value'} //values that can be used via process {$Environment} while step proceeding
});
```

{% endcode %}

</details>

<details>

<summary>completeParentStep</summary>

Proceeds a parent process step. Throws `WR_BPM.LimitsException` when a new transaction is required.

**Usage:**

{% code overflow="wrap" %}

```apex
completeParentStep(String cursorId, String operation, String comments (optional), Date startDate (optional), Date completeDate (optional))
```

{% endcode %}

**Return Value:** Boolean //if proceed executed successfully

**Example:**

{% code overflow="wrap" %}

```apex
new WR_BPM.API().call('WorkflowProceedService', 'completeParentStep', new Map<String, Object>{
  'cursorId' => Flow_Instance_Cursor__c.Id,
  'operation' => 'Proceed|Approve|Reject',
  'comments' => 'Some Comment', 
  'startDate' =>  Actual End DateTime, 
  'completeDate' => Actual End DateTime 
});
```

{% endcode %}

</details>

<details>

<summary>completeStepAsync</summary>

Proceeds a process step asynchronously.

**Usage:**

{% code overflow="wrap" %}

```apex
completeStepAsync(String flowInstanceCursorId, String operation, String stepId (optional), String comments (optional), String stepId, Date startDate (optional), Date completeDate (optional))
```

{% endcode %}

**Return Value:** none

**Example:**

{% code overflow="wrap" %}

```apex
new WR_BPM.API().call('WorkflowProceedService', 'completeStepAsync', new Map<String, Object>{
  'cursorId' => Flow_Instance_Cursor__c.Id,
  'operation' => 'Proceed|Approve|Reject',
  'stepId' =>  Flow_Instance_Cursor__c.Step__c, 
  'comments' => 'Some Comment', 
  'startDate' => Actual Start DateTime, 
  'completeDate' => Actual End DateTime
});
```

{% endcode %}

</details>

## WorkflowService

<details>

<summary>activateFlowInstances</summary>

Activates or deactivates the specified flow instances.

**Usage**:

{% code overflow="wrap" %}

```apex
activateFlowInstances(String instancesIds, Boolean flag, Boolean withSubProcesses)
```

{% endcode %}

**Return Value**: none

**Example:**

{% code overflow="wrap" %}

```apex
new WR_BPM.API().call('WorkflowService', 'activateFlowInstances', new Map<String, Object>{
  'instancesIds' => "["instanceId_1","instanceId_2", ...]",
  'flag' => true/false, // use true to activate instances, false to deactivate them 
  'withSubProcesses' => true/false // use true to activate instances along with their subprocesses
});
```

{% endcode %}

</details>

<details>

<summary>changeAssignee</summary>

Changes the assignee for the specified cursor.

**Usage**:

{% code overflow="wrap" %}

```apex
changeAssignee(String cursorId, String assigneeType, String assignee)
```

{% endcode %}

**Return Value:** none

**Example:**

{% code overflow="wrap" %}

```apex
new WR_BPM.API().call('WorkflowService', 'changeAssignee', new Map<String, Object>{
  'cursorId' => Flow_Instance_Cursor__c.Id,
  'assigneeType' => User/Group/Role/Profile/System, //pick one
  'assignee' => ids in JSON array format or 'System' if assigneeType is System
});
```

{% endcode %}

</details>

<details>

<summary>changeDuration</summary>

Sets the duration for the specified task.

**Usage:**

{% code overflow="wrap" %}

```apex
changeDuration(String cursorId, String duration)
```

{% endcode %}

**Return Value:** none

**Example:**

{% code overflow="wrap" %}

```apex
new WR_BPM.API().call('WorkflowService', 'changeDuration', new Map<String, Object>{
  'cursorId' => Flow_Instance_Cursor__c.Id,
  'duration' => '1d 2h 30m' // [1d 1h 1m] format
});
```

{% endcode %}

</details>

<details>

<summary>refreshDuration</summary>

Recalculates the duration for an active step cursor.

**Usage:**

{% code overflow="wrap" %}

```apex
refreshDuration(String cursorId)
```

{% endcode %}

**Return Value:** none

**Example:**

{% code overflow="wrap" %}

```apex
new WR_BPM.API().call('WorkflowService', 'refreshDuration', new Map<String, Object>{
  'cursorId' => Flow_Instance_Cursor__c.Id
});
```

{% endcode %}

</details>

<details>

<summary>changeFlowStep</summary>

Moves the cursor to the specified process step.

**Usage:**

{% code overflow="wrap" %}

```apex
changeFlowStep(String cursorId, String targetStepId, Boolean complete)
```

{% endcode %}

**Return Value:** none

**Example:**

{% code overflow="wrap" %}

```apex
new WR_BPM.API().call('WorkflowService', 'changeFlowStep', new Map<String, Object>{
  'cursorId' => Flow_Instance_Cursor__c.Id,
  'targetStepId' => Flow_Step_Junction__c.Id, 
  'complete' => false // if set to true method will complete instance
});
```

{% endcode %}

</details>

<details>

<summary>changeStartDateConfig</summary>

Sets the start-date configuration for the specified cursor.

**Usage:**

{% code overflow="wrap" %}

```apex
changeStartDateConfig(String cursorId, String startDateConfig)
```

{% endcode %}

**Return Value**: none

**Example:**

{% code overflow="wrap" %}

```apex
new WR_BPM.API().call('WorkflowService', 'changeStartDateConfig',new Map<String, Object>{
  'cursorId' => Flow_Instance_Cursor__c.Id,
  'startDateConfig' => String.valueOf(system.today() +1)  // pass empty string to remove start date config from cursor
});
```

{% endcode %}

</details>

<details>

<summary>cloneInstance</summary>

Clones an existing flow instance and relates it to the specified record.

**Usage:**

{% code overflow="wrap" %}

```apex
cloneInstance(String instanceId, String recordId)
```

{% endcode %}

**Return Value:** Flow\_Instance\_\_c (new flow instance record)

**Example:**

{% code overflow="wrap" %}

```apex
new WR_BPM.API().call('WorkflowService', 'cloneInstance',new Map<String, Object>{
  'instanceId' => Flow_Instance__c.Id,
  'recordId' => context record id to relate new flow instance to
});
```

{% endcode %}

</details>

<details>

<summary>migrateFlowInstances</summary>

Migrates flow instances using the specified flow mapping. Migrated instances become inactive. Source instances remain.

**Usage:**

{% code overflow="wrap" %}

```apex
migrateFlowInstances(String sourceFlowId, String targetFlowId, String instances, String stepsMapping (Optional))
```

{% endcode %}

**Return Value:** List\<Flow\_Instance\_\_c> - migrated flow instances list

**Example:**

{% code overflow="wrap" %}

```apex
new WR_BPM.API().call('WorkflowService', 'migrateFlowInstances', new Map<String, Object>{
  'sourceFlowId' => Flow__c.Id, // source flow id 
  'targetFlowId' => Flow__c.Id, // target flow id 
  'instances' => 'select id from wr_bpm__flow_instance__c where id in ( \'instanceId_1\', \'instanceId_2\')', // SOQL query or Ids in JSON array format.
  'stepsMapping' => The JSON object in format {"SOURCE_STEP_ID OR SOURCE_STEP_NAME":"TARGET_STEP_ID OR TARGET_STEP_NAME", ...}, // optional
  'keepHistory' => true OR false // optional; defaults to false
});
```

{% endcode %}

</details>

<details>

<summary>reactivateReminders</summary>

Reactivates inactive reminders that already ran.

**Usage:**

{% code overflow="wrap" %}

```apex
reactivateReminders(String cursorId, List<ID> remindersIds)
```

{% endcode %}

**Return Value:** none

**Example:**

{% code overflow="wrap" %}

```apex
new WR_BPM.API().call('WorkflowService', 'reactivateReminders', new Map<String, Object>{
  'cursorId' => Flow_Instance_Cursor__c.Id,
  'remindersIds' => new List<ID>{'reminderId_1', 'reminderId_2'}
}); 
```

{% endcode %}

</details>

<details>

<summary>reactivateEscalations</summary>

Reactivates inactive escalations that already ran.

**Usage:**

{% code overflow="wrap" %}

```apex
reactivateEscalations(String cursorId, List<ID> escalationsIds)
```

{% endcode %}

**Return Value:** none

**Example:**

{% code overflow="wrap" %}

```apex
new WR_BPM.API().call('WorkflowService', 'reactivateEscalations', new Map<String, Object>{
  'cursorId' => Flow_Instance_Cursor__c.Id,
  'escalationsIds' => new List<ID>{'escalationId_1', 'escalationId_2'}
});
```

{% endcode %}

</details>

<details>

<summary>restartCursor</summary>

Restarts a flow instance cursor.

**Usage:**

{% code overflow="wrap" %}

```apex
restartCursor(ID cursorId)
```

{% endcode %}

**Return Value:** Flow\_Instance\_Cursor\_\_c

**Example:**

{% code overflow="wrap" %}

```apex
new WR_BPM.API().call('WorkflowService', 'restartCursor', Flow_Instance_Cursor__c.Id);
```

{% endcode %}

</details>

<details>

<summary>restartBranch</summary>

Restarts a flow instance branch.

**Usage:**

{% code overflow="wrap" %}

```apex
restartBranch(ID instanceId, ID branchId)
```

{% endcode %}

**Return Value:** Flow\_Instance\_Cursor\_\_c

**Example:**

{% code overflow="wrap" %}

```apex
new WR_BPM.API().call('WorkflowService', 'restartBranch', new Map<String,Object>{
  'instanceId' => Flow_Instance__c.Id,
  'branchId' => Flow_Branch__c.Id
});
```

{% endcode %}

</details>

<details>

<summary>restartInstance</summary>

Restarts a flow instance.

**Usage:**

{% code overflow="wrap" %}

```apex
restartInstance(ID instanceId, Boolean keepHistory)
```

{% endcode %}

**Return Value:** Flow\_Instance\_\_c

**Example:**

{% code overflow="wrap" %}

```apex
new WR_BPM.API().call('WorkflowService', 'restartInstance', new Map<String,Object>{
  'instanceId' => Flow_Instance__c.Id,
   'keepHistory' => true/false //will keep process history after restarting instance if set to 'true'
});
```

{% endcode %}

</details>

<details>

<summary>terminateCursor</summary>

Completes a flow instance cursor.

**Usage:**

{% code overflow="wrap" %}

```apex
terminateCursor(ID cursorId, ID stepId)
```

{% endcode %}

**Return Value:** none

**Example:**

{% code overflow="wrap" %}

```apex
new WR_BPM.API().call('WorkflowService', 'terminateCursor', new Map<String,Object>{
   'cursorId' => Flow_Instance_Cursor__c.Id,
    'stepId ' => Flow_Step_Junction__c.Id
});
```

{% endcode %}

</details>

<details>

<summary>terminateInstance</summary>

Completes a flow instance and optional subprocess instances.

**Usage:**

{% code overflow="wrap" %}

```apex
terminateInstance(ID instanceId, Boolean withSubProcesses, String comments)
```

{% endcode %}

**Return Value:** none

**Example:**

{% code overflow="wrap" %}

```apex
new WR_BPM.API().call('WorkflowService', 'terminateInstance', new Map<String,Object>{
   'instanceId' => Flow_Instance__c.Id,
   'withSubProcesses ' => true/false, // (will also complete subprocess instances if set to true
   'comments' => user comments
});
```

{% endcode %}

</details>

<details>

<summary>throwException</summary>

Throws a `WR_BPM.GenericException`.

**Usage:**

{% code overflow="wrap" %}

```apex
throwException(String message)
```

{% endcode %}

**Return Value:** none

**Example:**

{% code overflow="wrap" %}

```apex
new WR_BPM.API().call('WorkflowService', 'throwException', 'Message...');
```

{% endcode %}

</details>

<details>

<summary>updateActualDates</summary>

Updates actual dates on flow instance history.

**Usage:**

{% code overflow="wrap" %}

```apex
updateActualDates(String cursorOrHistoryId, Object startDate, Object endDate)
```

{% endcode %}

**Return Value:** none

**Example:**

{% code overflow="wrap" %}

```apex
new WR_BPM.API().call('WorkflowService', 'updateActualDates', new Map<String,Object>{
   'cursorOrHistoryId' => ID of flow instance cursor or flow instance history, 
   'startDate' =>  dateTime or 'IGNORE' if date should not be updated,
   'completeDate' => dateTime or 'IGNORE' if date should not be updated
});
```

{% endcode %}

</details>

<details>

<summary>updateManagers</summary>

Updates managers for the specified flow instance.

**Usage:**

{% code overflow="wrap" %}

```apex
updateManagers(ID instanceId, String managers)
```

{% endcode %}

**Return Value:** none

**Example:**

{% code overflow="wrap" %}

```apex
new WR_BPM.API().call('WorkflowService', 'updateManagers', new Map<String,Object>{
   'instanceId' => Flow_Instance__c.Id,
   'managers' => '["user1_ID", "user2_ID", ....]'
});
```

{% endcode %}

</details>

<details>

<summary>updateProcessingFrequency</summary>

Updates processing frequency for the specified cursors.

**Usage:**

{% code overflow="wrap" %}

```apex
updateProcessingFrequency(String cursorsIds, Integer frequency)
```

{% endcode %}

**Return Value:** none

**Example:**

{% code overflow="wrap" %}

```apex
new WR_BPM.API().call('WorkflowService', 'updateProcessingFrequency', new Map<String,Object>{
   'cursorsIds' => '["cursorId_1", "cursorId_2", ...]',
   'frequency' => -1 / 0 / 4 / 8 / 12 / 24 / 48   //integer value of hours
});
```

{% endcode %}

</details>

<details>

<summary>updateProcessingFrequencyByObjectsAndSteps</summary>

Updates cursor processing frequency by object and step IDs.

**Usage:**

{% code overflow="wrap" %}

```apex
updateProcessingFrequencyByObjectsAndSteps(String objectStepMap, Integer frequency)
```

{% endcode %}

**Return Value:** none

**Example:**

{% code overflow="wrap" %}

```apex
new WR_BPM.API().call('WorkflowService', 'updateProcessingFrequencyByObjectsAndSteps', new Map<String,Object>{
   'objectStepMap' => JSON object in format '{"object_id":["step_id", ...]}'
   'frequency' => -1 / 0 / 4 / 8 / 12 / 24 / 48   //integer value of hours
});
```

{% endcode %}

</details>

## VariableService

<details>

<summary>updateVariable</summary>

Updates one variable on a flow instance. Creates it when absent.

**Usage:**

{% code overflow="wrap" %}

```apex
updateVariable(String instanceId, String name, Object value)
```

{% endcode %}

**Return Value:** none

**Example:**

{% code overflow="wrap" %}

```apex
new WR_BPM.API().call('VariableService', 'updateVariable', new Map<String, Object>{
  'instanceId' => Flow_Instance__c.Id, 
  'name' => 'variable_name', 
  'value' => {SOME_VALUE}
});
```

{% endcode %}

</details>

<details>

<summary>updateVariables</summary>

Updates multiple variables on a flow instance. Creates absent variables.

**Usage:**

{% code overflow="wrap" %}

```apex
updateVariables(String instanceId, Map<String, Object> variables)
```

{% endcode %}

**Return Value:** none

**Example:**

{% code overflow="wrap" %}

```apex
new WR_BPM.API().call('VariableService', 'updateVariables', new Map<String, Object>{
  'instanceId' => Flow_Instance__c.Id, 
  'variables' => new Map<String, Object>{'variable_name' => {SOME_VALUE}}
});
```

{% endcode %}

</details>

<details>

<summary>updateVariablesByInstances</summary>

Updates variables on specified flow instances.

**Usage:**

{% code overflow="wrap" %}

```apex
updateVariablesByInstances(List<String> instancesIds, Map<String, Object> variables)
```

{% endcode %}

**Return Value:** none

**Example:**

{% code overflow="wrap" %}

```apex
new WR_BPM.API().call('VariableService', 'updateVariables', new Map<String, Object>{
  'instancesIds' => List<String>{Flow_Instance__c.Id}, //flow instances ids 
  'variables' => new Map<String, Object>{'variable_name' => {SOME_VALUE}}
});
```

{% endcode %}

</details>

## FlowGanttService

<details>

<summary>recalculateGanttProperties</summary>

Recalculates process-step dates using flow and record IDs.

**Usage:**

{% code overflow="wrap" %}

```apex
recalculateGanttProperties(ID flowId, ID recordId, ID stepId, DateTime date)
```

{% endcode %}

**Return Value**: none

**Example:**

{% code overflow="wrap" %}

```apex
new WR_BPM.API().call('FlowGanttService', 'recalculateGanttProperties', new Map<String, Object>{
  'flowId' => The flow ID,
  'recordId' => The record ID,
  'stepId' => The step ID,
  'date' => The date/time when recalculation will be executed
});
```

{% endcode %}

</details>

<details>

<summary>recalculateGanttPropertiesByInstance</summary>

Recalculates process-step dates using an instance ID.

**Usage:**

{% code overflow="wrap" %}

```apex
recalculateGanttPropertiesByInstance(ID instanceId, ID stepId, DateTime date)
```

{% endcode %}

**Return Value**: none

**Example:**

{% code overflow="wrap" %}

```apex
new WR_BPM.API().call('FlowGanttService', 'recalculateGanttPropertiesByInstance', new Map<String, Object>{
  'instanceId' => The process instance ID,
  'stepId' => The step ID, 
  'date' => The date/time when recalculation will be executed
});
```

{% endcode %}

</details>

## SFWorkflowService

<details>

<summary>lock</summary>

Locks Salesforce records through the approval process.

**Usage:**

{% code overflow="wrap" %}

```apex
lock(String ids, Boolean allOrNothing)
```

{% endcode %}

**Return Value:** Approval.LockResult

**Example:**

{% code overflow="wrap" %}

```apex
new WR_BPM.API().call('SFWorkflowService', 'lock', new Map<String, Object>{
  'ids' => record ids in JSON format,
  'allOrNothing' => Boolean specifying whether this operation allows partial success. If you specify false and a record fails, the remainder of the DML operation can still succeed
});
```

{% endcode %}

</details>

<details>

<summary>unlock</summary>

Unlocks Salesforce records through the approval process.

**Usage:**

{% code overflow="wrap" %}

```apex
unlock(String ids, Boolean allOrNothing)
```

{% endcode %}

**Return Value:** Approval.LockResult

**Example:**

{% code overflow="wrap" %}

```apex
new WR_BPM.API().call('SFWorkflowService', 'lock', new Map<String, Object>{
  'ids' => record ids in JSON format,
  'allOrNothing' => Boolean specifying whether this operation allows partial success. If you specify false and a record fails, the remainder of the DML operation can still succeed
});
```

{% endcode %}

</details>

<details>

<summary>startFlow</summary>

Starts a Salesforce flow.

**Usage:**

{% code overflow="wrap" %}

```apex
startFlow(String namespace, String flowName, String variables)
```

{% endcode %}

**Return Value:** Flow\.Interview

**Example:**

{% code overflow="wrap" %}

```apex
new WR_BPM.API().call('SFWorkflowService', 'startFlow', new Map<String,Object>{
  'namespace' => organization namespace, optional, 
  'flowName' => Sales Force flow name, 
  'variables' => JSON object
});
```

{% endcode %}

</details>

## LicenseService service

<details>

<summary>addLicenseUser</summary>

Adds a license to one user.

**Usage:**

{% code overflow="wrap" %}

```apex
addLicenseUser(String license, String user ID)
```

{% endcode %}

**Return Value:** WR\_BPM\_\_License\_User\_\_c object

**Example:**

{% code overflow="wrap" %}

```apex
new WR_BPM.API().call('LicenseService', 'addLicenseUser', new Map<String, Object>{
  'license' => The license Id or Name,
  'userId' => user ID
});
```

{% endcode %}

</details>

<details>

<summary>removeLicenseUser</summary>

Revokes a license from one user.

**Usage:**

{% code overflow="wrap" %}

```apex
removeLicenseUser(String license, String user ID)
```

{% endcode %}

**Example:**

{% code overflow="wrap" %}

```apex
new WR_BPM.API().call('LicenseService', 'removeLicenseUser', new Map<String, Object>{
  'license' => The license Id or Name,
  'userId' => user ID
});
```

{% endcode %}

</details>

<details>

<summary>addLicenseUsers</summary>

Adds a license to specified users.

**Usage:**

{% code overflow="wrap" %}

```apex
addLicenseUsers(String license, String user IDs)
```

{% endcode %}

**Return Value:** WR\_BPM\_\_License\_User\_\_c object

**Example:**

{% code overflow="wrap" %}

```apex
new WR_BPM.API().call('LicenseService', 'addLicenseUsers', new Map<String, Object>{
  'license' => The license Id or Name,
  'usersIds' => The users Ids in JSON array format
});
```

{% endcode %}

</details>

<details>

<summary>removeLicenseUsers</summary>

Revokes a license from specified users.

**Usage:**

```apex
removeLicenseUsers(String license, String user IDs)
```

**Example:**

{% code overflow="wrap" %}

```apex
new WR_BPM.API().call('LicenseService', 'removeLicenseUsers', new Map<String, Object>{
  'license' => The license Id or Name,
  'usersIds' => The users Ids in JSON array format
});
```

{% endcode %}

</details>
