### Create Bulk Action Configuration Record Source: https://context7.com/google/bulk-actions-framework/llms.txt Example Apex code demonstrating how to instantiate and populate a `Bulk_Action_Configuration__mdt` record with settings for a bulk action. ```apex // Bulk_Action_Configuration__mdt fields: // - DeveloperName: Unique API name (auto-generated from MasterLabel) // - MasterLabel: Display name of the bulk action // - Object_API_Name__c: Target Salesforce object // - Action_Flow_API_Name__c: Required. API name of the action flow // - Eval_Flow_API_Name__c: Optional. API name of evaluation flow // - Eval_Flow_Error_Message__c: Optional. Message for ineligible records // - Input_Flow_API_Name__c: Optional. API name of input screen flow // - Preview_Screen_Field_Set_API_Name__c: Required. Field set for preview table // - Preview_Screen_Button_Name__c: Optional. Custom button label (default: "Next") // - Required_Permission__c: Optional. Custom permission API name for access control // - Custom_Success_Message__c: Required if async mode. Message after action completes // - Is_Action_Flow_Execution_in_Async_Mode__c: Boolean for async execution // Example configuration record Bulk_Action_Configuration__mdt config = new Bulk_Action_Configuration__mdt( MasterLabel = 'Close Multiple Cases', DeveloperName = 'Close_Multiple_Cases', Object_API_Name__c = 'Case', Action_Flow_API_Name__c = 'Close_Case_Action', Eval_Flow_API_Name__c = 'Check_Case_Can_Close', Eval_Flow_Error_Message__c = 'The following cases cannot be closed because they have open tasks.', Input_Flow_API_Name__c = 'Capture_Close_Reason', Preview_Screen_Field_Set_API_Name__c = 'Case_Close_Preview', Preview_Screen_Button_Name__c = 'Close Cases', Required_Permission__c = 'Close_Cases_Permission', Custom_Success_Message__c = 'Cases are being closed. This may take a few minutes.', Is_Action_Flow_Execution_in_Async_Mode__c = false ); ``` -------------------------------- ### Retrieve All Bulk Action Configurations Source: https://context7.com/google/bulk-actions-framework/llms.txt Use this Apex method to fetch all available bulk action configurations. It's designed for use in LWC components to populate setup lists. ```apex // BulkActionSetupListController.getConfig - Lists all configurations // Returns: List all configuration records @AuraEnabled(cacheable=true) public static List getConfig() { return Bulk_Action_Configuration__mdt.getAll().values(); } ``` ```javascript // Example LWC usage import getConfig from "@salesforce/apex/BulkActionSetupListController.getConfig"; getConfig() .then((result) => { // result = [ // { MasterLabel: 'Close Cases', DeveloperName: 'Close_Cases', Action_Flow_API_Name__c: '...', ... }, // { MasterLabel: 'Update Accounts', DeveloperName: 'Update_Accounts', Action_Flow_API_Name__c: '...', ... } // ] this.configurations = result; console.log(`Found ${result.length} configurations`); }) .catch((error) => { console.error('Failed to load configurations:', error.body.message); }); ``` -------------------------------- ### GET BulkActionExecutorController.getConfig Source: https://context7.com/google/bulk-actions-framework/llms.txt Retrieves and validates the Bulk_Action_Configuration__mdt metadata record by its developer name. ```APIDOC ## GET BulkActionExecutorController.getConfig ### Description Retrieves the bulk action configuration metadata record by developer name. This method validates that the configuration exists, the user has required permissions, and all mandatory fields are populated before returning the configuration. ### Method GET (Aura-enabled) ### Parameters #### Request Body - **configName** (String) - Required - The DeveloperName of the Bulk_Action_Configuration__mdt record ### Response #### Success Response (200) - **Bulk_Action_Configuration__mdt** (Object) - The configuration record containing flow associations, permission requirements, and success messages. ``` -------------------------------- ### LWC Usage for Inserting Configuration Source: https://context7.com/google/bulk-actions-framework/llms.txt Example JavaScript code for a Lightning Web Component to call the `insertConfig` Apex method. It demonstrates how to pass a configuration object and handle the asynchronous deployment result, including error logging. ```javascript import insertConfig from "@salesforce/apex/BulkActionSetupController.insertConfig"; const newConfig = { MasterLabel: 'Bulk Update Account Rating', Object_API_Name__c: 'Account', Action_Flow_API_Name__c: 'Update_Account_Rating_Action', Preview_Screen_Field_Set_API_Name__c: 'Account_Rating_Preview', Preview_Screen_Button_Name__c: 'Update Rating' }; insertConfig({ config: newConfig }) .then((result) => { if (result.errorMessage.length > 0) { console.error('Deploy errors:', result.errorMessage); } else { console.log('Deployment started. Job ID:', result.jobId); // Poll for deployment status or wait for callback } }) .catch((error) => { console.error('Failed to create config:', error.body.message); }); ``` -------------------------------- ### Get Preview Table Details (Apex) Source: https://context7.com/google/bulk-actions-framework/llms.txt Retrieves record data and column metadata for the preview screen. Uses a field set to define columns and returns a wrapper with column definitions and row data. Use this to populate the preview table before user confirmation. ```apex // BulkActionExecutorController.getTableDetails - Fetches preview table data // Input: recordIds - List of record IDs selected by user // Input: fieldSetName - API name of the field set for preview columns // Returns: BulkActionTable wrapper with columns and rows @AuraEnabled(cacheable=true) public static BulkActionTable getTableDetails( List recordIds, String fieldSetName ) { return BulkActionRecordDetailsFetcher.getTableDetails(recordIds, fieldSetName); } ``` ```javascript // Example usage from LWC import getTableDetails from "@salesforce/apex/BulkActionExecutorController.getTableDetails"; getTableDetails({ recordIds: ['5000000000001AAA', '5000000000002BBB', '5000000000003CCC'], fieldSetName: 'Case_Preview_Fields' }) .then((result) => { // result.objectName = 'Case' // result.selectedRecordIds = ['500...', '500...', '500...'] // result.returnURL = '/lightning/o/Case/list' // result.columns = [ // { label: 'Case Number', apiName: 'CaseNumber', fieldDataType: 'text', helpText: '...' }, // { label: 'Subject', apiName: 'Subject', fieldDataType: 'text', helpText: null }, // { label: 'Status', apiName: 'Status', fieldDataType: 'picklist', helpText: '...' } // ] // result.rows = [ // { displayRecord: {Id: '500...', CaseNumber: '00001', Subject: 'Test'}, isValid: true }, // ... // ] this.data = result; this.columns = result.columns; this.records = result.rows; }) .catch((error) => { console.error('Failed to load table:', error.body.message); }); ``` -------------------------------- ### GET BulkActionExecutorController.getTableDetails Source: https://context7.com/google/bulk-actions-framework/llms.txt Fetches record data and column metadata for displaying selected records in the preview screen. ```APIDOC ## GET BulkActionExecutorController.getTableDetails ### Description Retrieves record data and column metadata for displaying selected records in the preview screen. Uses a field set to determine which columns to display and returns a BulkActionTable wrapper containing both column definitions and row data. ### Method GET (Aura-enabled) ### Parameters #### Request Body - **recordIds** (List) - Required - List of record IDs selected by user - **fieldSetName** (String) - Required - API name of the field set for preview columns ### Response #### Success Response (200) - **BulkActionTable** (Object) - Wrapper containing objectName, selectedRecordIds, returnURL, columns, and rows. ``` -------------------------------- ### Get Bulk Action Configuration (Apex) Source: https://context7.com/google/bulk-actions-framework/llms.txt Retrieves and validates the Bulk Action Configuration metadata record. Ensures the configuration exists, the user has permissions, and mandatory fields are populated. Use this to fetch configuration details before executing an action. ```apex // BulkActionExecutorController.getConfig - Retrieves and validates configuration // Input: configName - The DeveloperName of the Bulk_Action_Configuration__mdt record // Returns: Bulk_Action_Configuration__mdt record if valid // Throws: BulkActionsException if configuration is invalid or user lacks permissions // Controller method (Aura-enabled, cacheable) @AuraEnabled(cacheable=true) public static Bulk_Action_Configuration__mdt getConfig(String configName) { Bulk_Action_Configuration__mdt config = BulkActionUtil.getConfig(configName); String exceptionMessage = BulkActionIOValidator.validateConfiguration(config); if (exceptionMessage != '') { throw new BulkActionsException(exceptionMessage); } return config; } ``` ```javascript // Example usage from LWC JavaScript import getConfig from "@salesforce/apex/BulkActionExecutorController.getConfig"; getConfig({ configName: 'Update_Case_Status' }) .then((result) => { // result contains: // - DeveloperName, MasterLabel // - Action_Flow_API_Name__c (required) // - Eval_Flow_API_Name__c (optional) // - Input_Flow_API_Name__c (optional) // - Preview_Screen_Field_Set_API_Name__c // - Preview_Screen_Button_Name__c // - Required_Permission__c // - Custom_Success_Message__c // - Is_Action_Flow_Execution_in_Async_Mode__c console.log('Config loaded:', result.MasterLabel); }) .catch((error) => { console.error('Error:', error.body.message); }); ``` -------------------------------- ### POST /BulkActionSetupController/insertConfig Source: https://context7.com/google/bulk-actions-framework/llms.txt Creates a new bulk action configuration record by deploying it via the Metadata API. ```APIDOC ## POST /BulkActionSetupController/insertConfig ### Description Creates a new bulk action configuration record via the Metadata API. Deploys the configuration asynchronously and returns a job ID for tracking. ### Method POST ### Request Body - **config** (Bulk_Action_Configuration__mdt) - Required - The configuration record containing fields like MasterLabel, Object_API_Name__c, and Action_Flow_API_Name__c. ### Request Example { "config": { "MasterLabel": "Bulk Update Account Rating", "Object_API_Name__c": "Account", "Action_Flow_API_Name__c": "Update_Account_Rating_Action", "Preview_Screen_Field_Set_API_Name__c": "Account_Rating_Preview", "Preview_Screen_Button_Name__c": "Update Rating" } } ### Response #### Success Response (200) - **jobId** (Id) - The ID of the metadata deployment job. - **errorMessage** (List) - A list of error messages if the deployment fails to enqueue. - **status** (String) - The current status of the operation. #### Response Example { "jobId": "0AfXXXXXXXXXXXX", "errorMessage": [], "status": "Queued" } ``` -------------------------------- ### Configure List View Button URL Source: https://context7.com/google/bulk-actions-framework/llms.txt Configures a URL for a list view button to invoke the Bulk Action Initializer flow with required parameters. ```javascript // List View Button URL formula (Detail Page Button or List Button) // Button Type: URL // Behavior: Display in existing window without sidebar or header /flow/Bulk_Action_Initializer?ids={!GETRECORDIDS($ObjectType.Case)}&bulkActionTemplateName=Close_Multiple_Cases&returnObjectName=Case // Explanation of URL parameters: // - ids: Comma-separated list of selected record IDs (uses GETRECORDIDS function) // - bulkActionTemplateName: DeveloperName of the Bulk_Action_Configuration__mdt record // - returnObjectName: Object API name for return navigation // Alternative using retURL for navigation /flow/Bulk_Action_Initializer?ids={!GETRECORDIDS($ObjectType.Account)}&bulkActionTemplateName=Update_Account_Rating&returnObjectName=Account&retURL=%2Flightning%2Fo%2FAccount%2Flist ``` -------------------------------- ### Insert Bulk Action Configuration via Metadata API Source: https://context7.com/google/bulk-actions-framework/llms.txt Apex controller method to create a new `Bulk_Action_Configuration__mdt` record using the Metadata API. It handles the conversion of Apex object fields to metadata values and enqueues an asynchronous deployment. Requires a `CustomMetadataCreateResult` inner class for the return type. ```apex // BulkActionSetupController.insertConfig - Creates new configuration // Input: config - Bulk_Action_Configuration__mdt record to create // Returns: CustomMetadataCreateResult with jobId or errorMessage @AuraEnabled public static CustomMetadataCreateResult insertConfig( Bulk_Action_Configuration__mdt config ) { CustomMetadataCreateResult result = new CustomMetadataCreateResult(); Metadata.CustomMetadata customMetadata = new Metadata.CustomMetadata(); customMetadata.fullName = 'Bulk_Action_Configuration__mdt.' + convertToAPIName(config.MasterLabel); customMetadata.Label = config.MasterLabel; // Add all field values from config Map fieldMap = Schema.getGlobalDescribe() .get('Bulk_Action_Configuration__mdt').getDescribe().fields.getMap(); for (String fieldName : fieldMap.keySet()) { Schema.DescribeFieldResult fieldRes = fieldMap.get(fieldName).getDescribe(); if (config.get(fieldRes.getName()) != null && fieldRes.getName() != 'MasterLabel') { Metadata.CustomMetadataValue fieldData = new Metadata.CustomMetadataValue(); fieldData.field = fieldRes.getName(); fieldData.value = config.get(fieldRes.getName()); customMetadata.values.add(fieldData); } } Metadata.DeployContainer mdContainer = new Metadata.DeployContainer(); mdContainer.addMetadata(customMetadata); BulkActionCustomMetadataCallback callback = new BulkActionCustomMetadataCallback(); try { result.jobId = Metadata.Operations.enqueueDeployment(mdContainer, callback); } catch (AsyncException exp) { result.errorMessage.add(exp.getMessage()); } return result; } // CustomMetadataCreateResult wrapper public class CustomMetadataCreateResult { @AuraEnabled public Id jobId { get; set; } @AuraEnabled public List errorMessage { get; set; } @AuraEnabled public String status { get; set; } } ``` -------------------------------- ### Execute Action Flow in Apex and LWC Source: https://context7.com/google/bulk-actions-framework/llms.txt Performs bulk actions by invoking an action flow, optionally re-evaluating records first. LWC integration supports passing user inputs captured from screen flows. ```apex // BulkActionExecutorController.executeActionFlow - Performs the bulk action // Input: table - BulkActionTable wrapper with record data // Input: config - Bulk_Action_Configuration__mdt configuration // Input: screenFlowInputs - Map of user inputs from optional Input Flow // Returns: List with actionStatus and actionErrorMessage @AuraEnabled public static List executeActionFlow( BulkActionTable table, Bulk_Action_Configuration__mdt config, Map screenFlowInputs ) { String evalFlowApiName = config.Eval_Flow_API_Name__c; String actionFlowApiName = config.Action_Flow_API_Name__c; List actionRows = new List(); if (evalFlowApiName != null) { // Re-evaluate to catch any changes since preview actionRows = reEvalEvalFlowForActionFlow(table, evalFlowApiName); } else { actionRows = table.rows; } table.rows = actionRows; List results = BulkActionUtil.invokeBulkActionFlows( table, actionFlowApiName, BulkActionConstants.FLOW_TYPE_ACTION, screenFlowInputs ); return amendActionResult(config, actionRows, results); } ``` ```javascript // Example LWC usage with user inputs from Input Flow import executeActionFlow from "@salesforce/apex/BulkActionExecutorController.executeActionFlow"; // After Input Flow completes and captures user data handleInputFlowStatusChange(event) { if (event.detail.status === 'FINISHED') { const capturedInputs = {}; event.detail.outputVariables.forEach(variable => { capturedInputs[variable.name] = variable.value; }); // capturedInputs = { newStatus: 'Closed', resolution: 'Resolved by support' } executeActionFlow({ table: this.data, config: this.config, screenFlowInputs: capturedInputs }) .then((result) => { // result = [ // { displayRecord: {...}, actionStatus: 'Success', actionErrorMessage: null }, // { displayRecord: {...}, actionStatus: 'Error', actionErrorMessage: 'FIELD_CUSTOM_VALIDATION_EXCEPTION' }, // { displayRecord: {...}, actionStatus: 'Pending', actionErrorMessage: null } // async mode // ] this.records = result; this.showResultScreen = true; }) .catch((error) => { console.error('Action failed:', error.body.message); }); } } ``` -------------------------------- ### BulkActionTable Apex Class Source: https://context7.com/google/bulk-actions-framework/llms.txt Defines the structure for bulk action data, including column definitions, row data, and navigation URLs. Use this class to encapsulate data for the bulk action UI. ```apex // BulkActionTable - Main wrapper for bulk action data public inherited sharing class BulkActionTable { @AuraEnabled public String objectName { get; set; } @AuraEnabled public List selectedRecordIds { get; set; } @AuraEnabled public String returnURL { get; set; } @AuraEnabled public List columns { get; set; } @AuraEnabled public List rows { get; set; } public BulkActionTable( String objectName, List selectedRecordIds, List columns, List rows ) { this.objectName = objectName; this.selectedRecordIds = selectedRecordIds; this.columns = columns; this.rows = rows; this.returnURL = URL.getOrgDomainUrl().toExternalForm() + '/lightning/o/' + this.objectName + '/list'; } // Column definition for preview table public class Column { @AuraEnabled public String label { get; set; } @AuraEnabled public String apiName { get; set; } @AuraEnabled public String fieldDataType { get; set; } @AuraEnabled public String helpText { get; set; } } // Row data with evaluation and action results public class Row { @AuraEnabled public sObject displayRecord { get; set; } @AuraEnabled public Boolean isValid { get; set; } // From eval flow @AuraEnabled public String outputMessage { get; set; } // From eval flow @AuraEnabled public String actionStatus { get; set; } // Success/Error/Pending @AuraEnabled public String actionErrorMessage { get; set; } // Error details public Row() { this.isValid = true; // Default to valid if no eval flow } } } ``` ```apex // Example test data creation @IsTest public static BulkActionTable getSampleTable() { BulkActionTable.Column col = new BulkActionTable.Column(); col.label = 'Case Number'; col.apiName = 'CaseNumber'; col.fieldDataType = 'text'; BulkActionTable.Row row = new BulkActionTable.Row(); row.displayRecord = new Case(Id = '5000000000001AAA', CaseNumber = '00001'); row.isValid = true; return new BulkActionTable( 'Case', new List{ '5000000000001AAA' }, new List{ col }, new List{ row } ); } ``` -------------------------------- ### BulkActionTable Class Structure Source: https://context7.com/google/bulk-actions-framework/llms.txt Defines the structure of the BulkActionTable class, including its properties for object context, selected records, and the nested Column and Row classes. ```APIDOC ## BulkActionTable Class ### Description The BulkActionTable class encapsulates all data needed for the bulk action UI, including column definitions, row data, and navigation URLs. ### Properties - **objectName** (String) - The API name of the Salesforce object. - **selectedRecordIds** (List) - A list of IDs for the records selected for the bulk action. - **returnURL** (String) - The URL to navigate back to after the action is completed. - **columns** (List) - Definitions for the preview table columns. - **rows** (List) - Data rows containing record information and action status. ### Nested Classes #### Column - **label** (String) - Display label for the column. - **apiName** (String) - Field API name. - **fieldDataType** (String) - Data type of the field. - **helpText** (String) - Tooltip help text. #### Row - **displayRecord** (sObject) - The record data to display. - **isValid** (Boolean) - Indicates if the record passed evaluation. - **outputMessage** (String) - Message returned from the evaluation flow. - **actionStatus** (String) - Current status of the action (Success/Error/Pending). - **actionErrorMessage** (String) - Error details if the action failed. ``` -------------------------------- ### Evaluation Flow Template for Record Eligibility Source: https://context7.com/google/bulk-actions-framework/llms.txt This XML structure defines an evaluation flow that determines a record's eligibility. It requires an input 'record' and must output a boolean 'isValid'. An optional 'outputMessage' string can also be provided. ```xml record SObject Case true false isValid Boolean false true false outputMessage String false true Set_Valid isValid Assign true Set_Invalid isValid Assign false outputMessage Assign Case has open tasks that must be completed first ``` -------------------------------- ### Execute Evaluation Flow in Apex and LWC Source: https://context7.com/google/bulk-actions-framework/llms.txt Executes an evaluation flow to determine record eligibility. The Apex method returns updated rows with validity status, which can then be processed in LWC. ```apex // BulkActionExecutorController.executeEvaluationFlow - Filters records by criteria // Input: table - BulkActionTable wrapper with record data // Input: evalFlowApiName - API name of the evaluation flow // Returns: List with isValid and outputMessage updated @AuraEnabled public static List executeEvaluationFlow( BulkActionTable table, String evalFlowApiName ) { List results = BulkActionUtil.invokeBulkActionFlows( table, evalFlowApiName, BulkActionConstants.FLOW_TYPE_EVAL ); for (Integer i = 0; i < table.rows.size(); i++) { Invocable.Action.Result result = results[i]; BulkActionTable.Row row = table.rows[i]; if (result.isSuccess()) { row.isValid = (Boolean) result.getOutputParameters().get('isValid'); row.outputMessage = (String) result.getOutputParameters().get('outputMessage'); } else { throw new AuraHandledException(getFormattedErrorMessage(result.getErrors())); } } return table.rows; } ``` ```javascript // Example LWC usage import executeEvaluationFlow from "@salesforce/apex/BulkActionExecutorController.executeEvaluationFlow"; executeEvaluationFlow({ table: this.data, evalFlowApiName: 'Check_Case_Eligibility' }) .then((result) => { // result = [ // { displayRecord: {...}, isValid: true, outputMessage: null }, // { displayRecord: {...}, isValid: false, outputMessage: 'Case is already closed' }, // { displayRecord: {...}, isValid: true, outputMessage: null } // ] this.records = result; const eligible = result.filter(row => row.isValid); const ineligible = result.filter(row => !row.isValid); console.log(`${eligible.length} eligible, ${ineligible.length} ineligible`); }) .catch((error) => { console.error('Evaluation failed:', error.body.message); }); ``` -------------------------------- ### Define Action Flow XML Source: https://context7.com/google/bulk-actions-framework/llms.txt Defines an action flow that updates record fields and includes a fault connector for error handling. ```xml record SObject Case true false closeReason String true false errorMessage String false true Update_Case_Fields record.Status Assign Closed record.Reason Assign closeReason Update_Case record Handle_Error Handle_Error errorMessage Assign $Flow.FaultMessage ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.