Execute APEX
Code needed
An example of custom apex class implementation (which is executed in "Execute Apex" action). WR requires these classes to follow certain rules. So pleaseimplement your class exactly like this.
Here is the example:
public without sharing class YourClassName implements STSWR1.WorkflowCallApexActionInterface
{
public class LimitsException extends Exception {}
public void run (SObject context, STSWR1__Flow_Instance_Cursor__c cursor, String operationType, String parameter)
{
Integer queriesNumber = 50; //select statements reservation: how many queries (approximately) consumes your class
Integer dmlsNumber = 50; //insert, update, delete statements reservation: how many DMLs (approximately) consumes your class
if (Limits.getQueries() + queriesNumber >= Limits.getLimitQueries()) throw new LimitsException('Not enough queries to execute this class.');
if (Limits.getDMLStatements() + dmlsNumber >= Limits.getLimitDMLStatements()) throw new LimitsException('Not enough DMLs to execute this class.');
//if you need you can reserve other limits (CPU time, Web callouts, etc.) in the similar way as above
try
{
//put your code here
}
catch(Exception ex)
{
//handle exception: e.g. save error message to a some text field in your record or send an email. Doing nothing is also an option but it's not recommended.
throw ex; //throw exception up the WR if you want your flow to stay in the current step.
}
}
}
0 Comments
Add your comment