flxbl-execution-framework

Availability

From

October 25

A powerful, flexible framework for managing and orchestrating business logic execution in Salesforce. This framework provides a unified approach to handling synchronous and asynchronous operations, with built-in support for error handling, retry logic, and execution tracking.

Why Execution Unit Framework?

The Problems We're Solving

1. Scattered Business Logic

In typical Salesforce implementations, business logic gets scattered across triggers, batch jobs, queueables, and various classes. This leads to:

  • Duplicate code across different execution contexts

  • Difficulty in maintaining and testing business logic

  • Inconsistent error handling and logging

2. Complex Asynchronous Patterns

Managing asynchronous operations in Salesforce is challenging:

  • Platform limits (5 queueable jobs from non-async context)

  • No built-in retry mechanisms

  • Difficult to track execution status and results

  • Complex chaining of async operations

3. Lack of Flexibility

Traditional approaches hardcode execution patterns:

  • A trigger always runs synchronously

  • A batch job always processes records in batches

  • Changing execution mode requires code refactoring

4. Poor Visibility and Control

Without a framework:

  • No central place to monitor execution status

  • Difficult to pause, resume, or rerun operations

  • Limited ability to track execution history and metrics

Our Solution

The Execution Unit Framework addresses these challenges by providing:

  • Unified execution model for all business logic

  • Declarative configuration of execution patterns

  • Automatic handling of platform limits and retries

  • Complete visibility into execution status and history

  • Flexible execution modes (sync/async) without code changes

Key Features

  • Unified Interface: Single ExecutionHandler interface for all business logic

  • Flexible Execution: Switch between synchronous and asynchronous execution without code changes

  • Built-in Persistence: Automatic tracking of execution status, results, and metrics

  • Automatic Unique Naming: UUID-based names prevent conflicts without developer intervention

  • Correlation Tracking: Automatic correlation IDs to group related execution units

  • Parent-Child Relationships: Track execution hierarchies with parent-child relationships

  • Error Handling: Comprehensive error capture and retry mechanisms

  • Chaining Support: Easy orchestration of complex multi-step processes

  • Platform Limit Management: Automatic handling of governor limits

  • Security: Built-in permission sets for admin and read-only access

  • Monitoring: Custom object for tracking and monitoring executions

Getting Started

Installation

  1. Deploy the framework to your Salesforce org:

  1. Assign permissions:

Your First Execution Handler

Let's start with a simple example - a handler that welcomes new accounts:

Creating an Execution Unit

Now, let's create an execution unit that uses our handler:

Automatic Naming Convention

The framework automatically generates unique names for all Execution Units using UUID suffixes:

  • Without custom name: Uses handler class name + UUID

    • Example: AccountSyncHandler_a1b2c3d4-e5f6-7890-abcd-ef1234567890

  • With custom name: Uses your provided name + UUID

    • Example: Daily Report_a1b2c3d4-e5f6-7890-abcd-ef1234567890

This ensures:

  • ✅ No naming conflicts when creating multiple units

  • ✅ Developers don't need to worry about uniqueness

  • ✅ Names remain readable with meaningful prefixes

  • ✅ UUID generation has minimal CPU impact using Crypto.GenerateAESKey(128)

Correlation Tracking

The framework automatically tracks related execution units using correlation IDs:

Automatic Correlation ID Generation

Every execution unit gets a correlation ID automatically:

Parent-Child Relationships

Child units automatically inherit their parent's correlation ID:

Explicit Correlation ID

You can provide your own correlation ID to group related units:

Querying Related Units

Basic Execution

From a Trigger

From an API or Lightning Component

Intermediate Patterns

Asynchronous Execution

Sometimes you want to offload work to run asynchronously to avoid governor limits:

Configure for async execution:

Execute from a batch or screen flow:

Conditional Execution with Scheduling

You can schedule execution units to run at specific times or under certain conditions:

Schedule it to skip weekends:

Error Handling and Retry Logic

Build robust handlers with retry capabilities:

Advanced Scenarios

Chaining Execution Units

One of the most powerful features is the ability to chain execution units for complex workflows with automatic correlation tracking:

Batch Processing with Execution Units

Process large data volumes efficiently:

Platform Event Driven Execution

Trigger execution units from platform events:

Complex Orchestration with State Management

Build sophisticated workflows with state management:

What to lookout for?

1. Handler Design

  • Keep handlers focused on a single responsibility

  • Use AbstractExecutionHandler for common patterns

  • Always validate input in your handlers

  • Return meaningful data in ExecutionResult

  • Don't worry about name uniqueness - UUID generation is automatic

2. Error Handling

  • Use try-catch blocks in handlers

  • Return descriptive error messages

  • Implement retry logic for transient failures

  • Log errors for debugging

3. Performance

  • Use async mode for long-running operations

  • Batch large datasets into chunks

  • Consider platform limits when chaining

  • Monitor execution metrics

4. Security

  • Validate all input data

  • Use with sharing in handlers when appropriate

  • Assign appropriate permission sets

  • Don't store sensitive data in Payload__c

5. Testing

  • Write comprehensive tests for handlers

  • Test both success and failure scenarios

  • Mock external dependencies

  • Test async execution paths

6. Monitoring

  • Use the ExecutionUnit__c list views

  • Set up alerts for failed executions

  • Regular cleanup of old execution records

  • Monitor execution patterns and performance

7. Naming Best Practices

  • Use descriptive names that indicate the handler's purpose

  • Don't add timestamps or random suffixes for uniqueness (UUID handles this)

  • Use ReferenceId__c field for business-specific identifiers

  • Keep names concise - the framework ensures they fit within the 255 character limit

Examples

Complete Workflow with Correlation Tracking

Here's a real-world example showing how correlation IDs track a complete order processing workflow:

Example Handlers

The framework includes several example handlers in the apps/examples directory:

  • AccountSyncHandler - Synchronizes account data

  • DataCleanupHandler - Cleans up old records

  • EmailNotificationHandler - Sends email notifications

  • AsyncExecutionHandler - Demonstrates async patterns

Troubleshooting

Common Issues

Execution not starting:

  • Check if unit is OnHold__c = true

  • Verify SkipUntil__c date hasn't passed

  • Ensure handler class exists and is global/public

Handler not found:

  • Verify class name is correct

  • Check if class implements ExecutionHandler

  • Ensure class is accessible (global/public)

Async execution limits:

  • Monitor queueable job limits

  • Use batch processing for large volumes

  • Implement proper chaining delays

Duplicate name errors (pre-UUID version):

  • This should not occur in the current version

  • All names are automatically made unique with UUID suffixes

  • If upgrading from older version, consider data migration

Finding specific execution units:

  • Use Name LIKE 'YourPrefix%' in SOQL queries

  • Use HandlerClassName__c field for exact handler matching

  • Use ReferenceId__c for business-specific lookups

  • Use CorrelationId__c to find all related units in a workflow

  • Use ParentExecutionUnit__c to find direct child units

Last updated