Recalculating compliance assignments after a matrix change

Recalculating compliance assignments after a matrix change

What it is

Compliance Items are recalculated automatically when an assignment is created, when evidence changes and during the daily expiry sweep. Changing the Compliance Matrix itself (for example an expiry window going from 30 to 60 days, a new requirement, or an edited applicability rule) does not touch existing items until they are recalculated.

The 3B Compliance Recalculation component and the 3B Recalculate Compliance Assignments (Batch) Flow action re-run the engine for existing assignments in a background batch job.

Recalculation is safe to repeat. It never overwrites what people entered: checklist ticks, waivers, approvals, verification notes and entered dates are preserved. It only recomputes engine-owned fields (status, applicability, evidence, dates).

Who can use it

Users with create and edit access on Compliance Assignment (included in the Onboarding_Admin_Full_Permission permission set).

The record page component

The component ships on the packaged Compliance Matrix record page, under the requirement builder. To add it to a custom page, open Lightning App Builder on a Compliance Matrix page and drag in 3B Compliance Recalculation. It has no properties.

Control What it does
Assigned on or after / on or before Only assignments created in this date range (the running user's timezone, both ends inclusive). Leave blank for no limit.
Contacts: Only some contacts... Opens the rule builder. Only assignments whose Contact passes the rule are recalculated. Clear removes the rule.
Active assignments in scope Live count of active assignments of this matrix that match the date range. The contact rule is checked during the run, so the real number may be lower.
Recalculate Starts the batch job. Disabled while a recalculation is running or when nothing is in scope.
Progress bar Batches processed out of the total, refreshed every 2 seconds. Turns red if the job fails or any batch errors. Reloading the page re-attaches to a recalculation that is still running.

Only active assignments (b3o__Active__c = true) are recalculated. Assignments whose matrix is inactive are skipped by the engine.

Flow action

3B Recalculate Compliance Assignments (Batch), category 3B Onboarding.

Input Type Description
Compliance Matrix Ids Id collection Matrices whose active assignments are recalculated. Blank = every matrix.
Assignment Created From Date Only assignments created on or after this date.
Assignment Created To Date Only assignments created on or before this date.
Contact Rule (JSON) Text Rule builder JSON evaluated against each assignment's Contact. Only contacts that pass are recalculated.
Batch Size Number Assignments per batch execution. Default 5, max 50.

Output: the batch job Id (text), one per request. Track it in Setup > Apex Jobs.

Unlike the other recalculation actions, this one faults the flow when the input is invalid (Created From after Created To, or a Contact Rule that is not valid JSON), so a misconfigured filter never silently does nothing.

Each request starts its own batch job. Call it once (a scheduled flow, a screen flow or an autolaunched flow run on demand), not from a record-triggered flow that fires per record: Salesforce allows 5 running batch jobs and 100 waiting in the flex queue.

Contact rule JSON

Build the rule once with the component's rule builder, or copy an applicability rule from a Compliance Requirement (b3o__Applicability_Rule__c): it is the same format. See the rule builder reference. A rule that errors for a contact excludes that contact and logs the error.

Apex

b3o.ComplianceMatrixRecalcBatch.Requests request = new b3o.ComplianceMatrixRecalcBatch.Requests();
request.matrixIds = new List<Id>{ 'a0X...' };
request.createdFrom = Date.newInstance(2026, 1, 1);
List<String> jobIds = b3o.ComplianceMatrixRecalcBatch.recalculate(
    new List<b3o.ComplianceMatrixRecalcBatch.Requests>{ request });

The raw SOQL form still works for anything the filters cannot express:

Database.executeBatch(new b3o.ComplianceMatrixRecalcBatch(
    'SELECT Id FROM b3o__Compliance_Assignment__c WHERE b3o__Active__c = true AND b3o__Last_Evaluated__c < LAST_N_DAYS:30'), 5);

Troubleshooting

Symptom Cause
Bar stays on "Waiting for Salesforce to start the job" The job is queued behind other batch jobs (Setup > Apex Flex Queue).
Job completes but some items did not change The contact rule excluded those contacts, the assignment is inactive, or the matrix is inactive.
"failed" count above zero A batch hit an error. Details are in the 3B error log; the remaining batches still run.
"You need create and edit access to Compliance Assignments" Assign Onboarding_Admin_Full_Permission.