Start an Action from an Apex Class
On this page
Start any Manipulate action from an Apex Class. The actions are provided as macros, reducing the need for configuration. The class will invoke a flow that runs the Manipulate action on the selected records.
This article is about starting a Manipulate Action in an Apex Class. For running an Apex Class as a Manipulate Action, see Run An Apex Class action.
In an Apex Class, you can add methods to apply a Manipulate action to a single record, or to a collection of records. The Manipulate action is preconfigured in a Macro, to make sure it can be run straight away without any further configuration.
A Manipulate action applied to a collection of records will be executed as a Manipulate Job. Its progress can be tracked on the Manipulate Job Overview page, but you can also add a method to the class to retrieve the job status.
Prerequisites
To start a Manipulate Action from an Apex Class, you need:
The Manipulate Action you want to run, preconfigured in a Macro.
- The macro should be intended for the same object as the records called in the class.
Some macros can be used for all objects (e.g. macros based on Mass Delete), but most are set up for one specific object. - Enable the macro for Start from an Apex Class for each applicable profile or user. In the Action Library, click Assignment to change this.
- Note down the API name of the macro. You can find the macro API name in the Action Library. The macro API name always starts with "macro-".

Read more about creating Macros here: Macros.
Run Manipulate Action on a single record
Define the following parameters in the method:
input.flowInvokerReference = 'yourClassName' The name of your class will be shown in the Manipulate record audit log (if enabled) to indicate what invoked the flow that executed the action.
input.dapMacroApiName = 'macro-yourMacro' The API name of the macro, that you noted down earlier (see Prerequisites).
input.recordId = Id.valueOf('a0P17000005cSNgEAM') The ID of the record that will be passed on to your macro. The object type of this recordId should be the same object type as configured in the macro.
The method for running a Manipulate Action on a single record will then be:
plauti.dapApexApiV1.RunMacroOnRecordInput input = new plauti.dapApexApiV1.RunMacroOnRecordInput();
input.flowInvokerReference = 'yourClassName';
input.dapMacroApiName = 'macro-yourMacro';
input.recordId = Id.valueOf('a0P17000005cSNgEAM');
plauti.dapApexApiV1 dapApexApi = new plauti.dapApexApiV1();
try {
plauti.dapApexApiV1.RunMacroOnRecordOutput output = dapApexApi.runMacroOnRecord(input);
} catch (plauti.dapApexApiV1.dapApiInternalException e) {
System.debug('Internal Plauti Manipulate exception. Please contact Plauti Support. ' + e.getMessage());
} catch (plauti.dapApexApiV1.dapApiExternalException e) {
System.debug('External Plauti Manipulate exception. Please check the provided input. ' + e.getMessage());
} catch (Exception e) {
System.debug('Exception. Please contact your SalesForce admin. ' + e.getMessage());
}
Run a Manipulate Job on a collection of records
Note that the action can process a maximum of 1560 record IDs.
Define the following parameters in the method:
input.flowInvokerReference = 'yourClassName' The name of your class will be shown in the Manipulate record audit log (if enabled) to indicate what invoked the flow that executed the action.
input.dapMacroApiName = 'macro-youMacro' The API name of the macro, that you noted down earlier (see Prerequisites).
input.recordIds = new List<Id>{
Id.valueOf('a0P17000005cSNgEAM'),
Id.valueOf('a0P17000005cSNgEAM')}; IDs of the records that will be passed on to your macro.
The object type of these recordIds should be the same object type as configured in the macro.
The list should contain a maximum of 1560 record IDs.
The method for running a Manipulate Action on a collection of records will then be:
plauti.dapApexApiV1.RunMacroJobOnRecordsInput input = new plauti.dapApexApiV1.RunMacroJobOnRecordsInput();
input.flowInvokerReference = 'yourClassName';
input.dapMacroApiName = 'macro-youMacro';
input.recordIds = new List<Id>{
Id.valueOf('a0P17000005cSNgEAM'),
Id.valueOf('a0P17000005cSNgEAM')
};
plauti.dapApexApiV1 dapApexApi = new plauti.dapApexApiV1();
try {
plauti.dapApexApiV1.RunMacroJobOnRecordsOutput output = dapApexApi.runMacroJobOnRecords(input);
Id dapFlowId = output.dapFlowId;
} catch (plauti.dapApexApiV1.dapApiInternalException e) {
System.debug('Internal Plauti Manipulate exception. Please contact Plauti Support. ' + e.getMessage());
} catch (plauti.dapApexApiV1.dapApiExternalException e) {
System.debug('External Manipulate exception. Please check the provided input. ' + e.getMessage());
} catch (Exception e) {
System.debug('Exception. Please contact your SalesForce admin. ' + e.getMessage());
}
The dapFlowId output, Id dapFlowId = output.dapFlowId , can then be used to fetch the status of the Manipulate Job.
Get the Manipulate Job status
When you started an action on a collection of records, it will be executed as a Manipulate Job. Its progress can be tracked on the Manipulate Job Overview page, but you can also add a method to the class to retrieve the job status. Use the dapFlowId output from the previous method for this.
Define the following parameter in the method:
input.dapFlowId = 'My Apex Manipulate Job'; The ID of the Manipulate Flow, received from RunMacroJobOnRecordsOutput
The method for fetching the Manipulate Job status will then be:
plauti.dapApexApiV1.GetDapJobStatusInput input = new plauti.dapApexApiV1.GetDapJobStatusInput();
input.dapFlowId = 'My Apex Manipulate Job';
plauti.dapApexApiV1 dapApexApi = new plauti.dapApexApiV1();
try {
plauti.dapApexApiV1.GetDapJobStatusOutput output = dapApexApi.getDapJobStatus(input);
} catch (plauti.dapApexApiV1.dapApiInternalException e) {
System.debug('Internal Plauti Manipulate exception. Please contact Plauti Support. ' + e.getMessage());
} catch (plauti.dapApexApiV1.dapApiExternalException e) {
System.debug('External Plauti Manipulate exception. Please check the provided input. ' + e.getMessage());
} catch (Exception e) {
System.debug('Exception. Please contact your SalesForce admin. ' + e.getMessage());
}
Note that you can also use the dapFlowId from a Manipulate Job that was started from a flow, as outlined in Start an Action in a Flow.
Results
The Single Record method returns the record ID and a summary of what was done, and it will state whether running the macro succeeded or failed:
| Parameter | Type | Content |
| recordId | ID | The ID of the record that was passed on to the macro. |
| summaryLine | String | A summary of what was done by the macro. |
| success | Boolean | An indication whether the macro execution succeeded or not. |
The Manipulate Job method for a collection of records returns the ID of the flow that executed the macro.
| Parameter | Type | Content |
| dapFlowId | ID | The ID of the flow that executed the macro. Use this ID in the 'Get Manipulate Job Status' method. |
The Get Manipulate Job Status method returns data about the Manipulate Job status. Note that the Manipulate Job status can also be tracked on the Job Overview page in Plauti Manipulate.
| Parameter | Type | Content |
| dapFlowId | ID | The ID of the flow that executed the macro you are fetching the Job status for. |
| startTime | Long | The starting time of the Manipulate Job (in Unix Epoch time) |
| endTime | Long | The ending time of the Manipulate Job (in Unix Epoch time) |
| status | String | The current status of the Manipulate Job, e.g. aborted, failed, running, etc. |
| isFinished | Boolean | A check whether the Manipulate Job is finished: is the status equal to 'finished' yes or no. |
Furthermore, the Audit Log (if enabled) and the Job Information on the Job Overview page (if a Manipulate Job action was used) will show that the macro was started from your class via a flow, with the class name you entered.