The break engine generates b3s__Break__c rows for shifts from configurable break rulesets. Admins model a jurisdiction's break law (or a client contract) as a b3s__Break_Ruleset__c with child b3s__Break_Rule__c rows; the engine resolves which ruleset applies to each shift, places the entitled breaks inside the shift window (with packaged placement logic or your own plugin), and materializes them as auto-created break records. The pay and bill engine then carves those breaks out of worked time (pay and bill sides independently) and detects missed-break premium pay.
Generation runs automatically from the Shift trigger, on demand from Apex, Flow, the remoting router or the Shift Rate Previewer, and as a pre-step of every Pay/Bill Runner batch.
Break_Ruleset__c (effective-dated; context lookups + Country/State jurisdiction; time source, rounding, plugin, premium cap)
└── Break_Rule__c (master-detail; one row = one break entitlement)
Shift__c ──< Break__c (+ Is_Billable__c, Break_Rule__c, Applied_Rule__c)
b3s__Valid_From__c / b3s__Valid_To__c (inclusive; blank Valid_To__c means open ended), b3s__Active__c. Dates are evaluated on the shift's local date (site timezone). A ruleset with a blank Valid_From__c, or a Valid_To__c before its Valid_From__c, is never effective.b3s__Contact__c, b3s__Work_Job__c, b3s__Work_Site__c, b3s__Account__c, b3s__Cost_Center__c: anchor the ruleset at a level of the resolution hierarchy, exactly like rate cards.b3s__Country__c and b3s__Province_State__c (Text). Matched case-insensitively and trimmed against the shift site's b3s__Country__c / b3s__Province_State__c, so a single "US-CA California" ruleset covers every site in that state without per-site wiring.b3s__Time_Source__c: Scheduled (label Prefer Scheduled, default) or Actual (label Prefer Actual, each actual falls back to scheduled): which shift window breaks are generated inside. Shift Billable_Start/End_Time__c win over it when set (each field on its own, timeSource = Billable), the same window the pay and bill engine prices. A shift with no usable window (no times, or end not after start) is skipped with a reason and its existing breaks are left untouched.b3s__Rounding_Interval__c (5/10/15/30/60 minutes, blank means no rounding), b3s__Start_Rounding__c / b3s__End_Rounding__c (Nearest, Up, Down; blank means Nearest). Each generated break's boundaries are rounded on the local wall clock.b3s__Plugin__c: Apex class implementing BreakPlugin; blank means the packaged default placement.b3s__Premium_Daily_Cap_Hours__c: maximum total missed-break premium hours per shift (California uses 2). b3s__Premium_Billable__c: when true, premium lines are emitted on the Bill side too, not just Pay.b3s__Description__c: long text for admin notes, for example legal caveats.One row is one break entitlement. Rules are evaluated in b3s__Priority__c ascending order (nulls last); b3s__Active__c = false rows are ignored.
b3s__Label__c: human name shown in traces ("First Meal Break"). b3s__Break_Type__c: Meal, Rest or Other (same values as Break__c.Type__c). b3s__Duration_Minutes__c: break length.b3s__Is_Paid__c / b3s__Is_Billable__c: stamped onto the generated break rows: these drive whether the pay and bill engine carves the break out of paid / billed time.b3s__Min_Work_Hours__c: the rule fires when the window length in hours is strictly greater than this ("work period over 5 hours" is entered as 5); blank means always fires. b3s__Max_Work_Hours__c: optional tier upper bound: fires only while the length is no greater than this. Two rules with Min 6 / Max 8 and Min 8 model Rhode Island's 20-minute-then-30-minute tiers.b3s__Placement__c: Start, Middle (default), End or Offset. Middle centres the break; Start / End sit it at the segment edges; Offset places a single occurrence at Earliest_Start_Hours after the window start.b3s__Earliest_Start_Hours__c: the break may not start before window start plus this many hours. b3s__Latest_End_Hours__c: the break must end by window start plus this many hours (California's "meal by the end of hour 5"). On premium detection this same field becomes the deadline a qualifying (full-duration) taken break must have ended by.b3s__Window_Start__c / b3s__Window_End__c (Time): an optional local wall-clock window (New York's 11:00–14:00 midday meal), intersected with the offset bounds on the local calendar day of the occurrence.b3s__Repeat_Every_Hours__c: recurring entitlement: occurrences = floor(length / every) plus one more when the remainder reaches b3s__Major_Fraction_Hours__c (California's rest break: one per 4 hours "or major fraction thereof" is Repeat 4, Fraction 2). Blank means a single occurrence.b3s__Premium_Type__c: blank means the rule carries no missed-break premium; otherwise Fixed Hours (pay b3s__Premium_Hours__c when violated: California's one hour of premium pay), Time Missed (pay the shortfall: required time minus the time covered by qualifying breaks), or Double Time Missed (twice the shortfall: Minnesota meals).b3s__Is_Billable__c (bill-side analog of b3s__Is_Paid__c), b3s__Break_Rule__c (lookup to the rule that generated an auto row), b3s__Applied_Rule__c (human trace, "US-CA California › First Meal Break"). Auto rows are marked b3s__Is_Auto_Created__c = true; manual rows never are.
b3s__Suppress_Break_Premiums__c: when checked, missed-break premium lines are not generated for the shift (for example the employee attested the missed break was their own election). Break generation itself is unaffected.
b3s__Hierarchy__c on the Default record overrides the resolution hierarchy order (see below). Absent, the shipped default applies.
The hierarchy order comes from Break_Setting__mdt.Default.Hierarchy__c (default Contact,Job,Site,Account,ParentAccount,CostCenter,State,Country,Default). The first six tokens match shift context Ids against the same-named ruleset lookups, exactly like rate card resolution; three jurisdiction levels follow:
| Token | Match |
|---|---|
| Contact | Shift__c.Contact__c to Break_Ruleset__c.Contact__c |
| Job | Work_Job__c to Work_Job__c |
| Site | Work_Site__c to Work_Site__c |
| Account | job account (Work_Job__r.Account__c), then site account (Work_Site__r.Account__c), to Account__c |
| ParentAccount | job account's ParentId, then site account's ParentId, to Account__c |
| CostCenter | Cost_Center__c to Cost_Center__c |
| State | site's Province_State__c matches the ruleset's, and the ruleset's Country__c is blank or matches the site's |
| Country | site's Country__c matches, and the ruleset's Province_State__c is blank |
| Default | all five context lookups and both jurisdiction fields blank: the org-wide fallback |
At the Account and ParentAccount levels the job's account is tried first and the site's account second; the first with an effective ruleset wins. Rate cards match the same accounts at the same levels, so one shift resolves its card and its ruleset on the same account. Jurisdiction text matching is case-insensitive and trimmed. The first level with a matching active, effective ruleset wins; ties break on latest Valid_From__c, then newest created. Effective dating is evaluated on the local date of the shift window start (scheduled, falling back to actual) in the site timezone. Unlike rate cards there is no temporal splitting: one ruleset governs the whole shift.
Populate Site Country. A state-level ruleset with
Country__c = 'US'only matches sites whoseb3s__Country__cis alsoUS. A site with a state but a blank country does not match it.
Resolution does not depend on the running user's access to ruleset records, so every user's shifts resolve the same ruleset. You can keep Break_Ruleset__c private to admins.
Every level walked is recorded as a ResolutionStep trace ("Matched on State level: US-CA California" / "Shift site has no state value"), rendered by the Shift Rate Previewer. No ruleset resolving simply means no auto breaks: it is not an error.
For each shift the engine:
Billable_Start/End_Time__c when set, else the ruleset's Time_Source__c (Prefer Scheduled / Prefer Actual with per-field fallback to scheduled). A shift with no usable window is skipped with a reason and keeps its existing break rows. A change to a billable field regenerates breaks like any other time change.b3s__Plugin__c class, or the packaged default placement when blank. A class that does not implement BreakPlugin fails the shift.b3s__Is_Auto_Created__c = false) of a given Type__c suppresses all auto breaks of that same Break_Type__c, with a trace step recording it. A worker who logged their own meal does not also get a generated one.Is_Auto_Created__c = true, Break_Rule__c, Applied_Rule__c ("Ruleset › Rule"), Is_Paid__c, Is_Billable__c, Type__c, Start__c, End__c. Manual rows are never touched. Re-running regenerates; it never duplicates.A failure on one shift never stops the others: that shift's BreakResult.error carries the message and its break rows stay as they were. BreakEngine.simulate(shiftIds) returns the same result with no DML (the previewer uses it).
Recurring breaks are spread evenly across the window, one per equal segment. Middle centres a break in its segment, Start and Offset sit at the segment start (Offset honours Earliest_Start_Hours for a single occurrence) and End sits at the segment end. Breaks always respect the rule's offset bounds and clock window. When the constraints cannot all be met, the break is placed at the nearest bound and its reason says so. Breaks never overlap. Each break carries a readable reason ("Shift length 10.5h > 5h: First Meal Break (30 min), occurrence 1 of 2 placed to end by hour 5").
When a worker or manager edits an auto-created break's Start__c, End__c or Type__c, the row's Is_Auto_Created__c flips to false. It becomes worker-owned and the engine stops regenerating or deleting it. Because the row's type now suppresses the matching auto rules, the edit sticks across regenerations.
Scheduled_Start/End_Time__c, Actual_Start/End_Time__c, Work_Site__c or Contact__c changed. Shifts whose b3s__Approval_Status__c is Submitted or Approved are skipped, so timesheet-locked shifts keep their breaks.Submitted and Approved shifts are excluded, so approved timesheets are priced against their locked break rows. A break-generation failure is added to the run's error log and never blocks pricing.The pay and bill engine detects missed-break premiums when it prices a shift. A shift qualifies only when it has both Actual_Start_Time__c and Actual_End_Time__c (the required window is the actual worked window) and b3s__Suppress_Break_Premiums__c is unchecked. For each premium-typed rule of the shift's resolved ruleset that fires for the actual worked length:
Is_Auto_Created__c = false) of the rule's Break_Type__c whose individual duration reaches Duration_Minutes__c count: two 15-minute meals do not satisfy one 30-minute meal. An untouched auto-generated row proves nothing about what the worker actually did.Latest_End_Hours__c additionally requires at least one qualifying break ending by window start plus that many hours: a late meal violates even at full duration, and a too-short break ending in time does not satisfy the deadline.Fixed Hours pays Premium_Hours__c once per violated rule; Time Missed pays the shortfall: max(0, occurrences × Duration_Minutes__c − min(qualifying, occurrences) × Duration_Minutes__c) ÷ 60: so a late-only violation pays 0; Double Time Missed pays twice that. The running total is capped at the ruleset's Premium_Daily_Cap_Hours__c per shift (each shift on the same day has its own cap).Fixed Hours rules only): auto breaks belonging to a violated Fixed Hours rule are not carved from the pay side: the worker worked through them and the fixed premium does not repay that time. This applies even when the cap clips the premium to zero. Time Missed / Double Time Missed rules keep the normal carve: their premium already pays the missed time, and uncarving too would double-pay it.Each violation emits a Pay staging line with Pay_Code__c = 'Missed_Break', Unit__c = 'Hours', quantity = the (cap-clipped) premium hours, rate = a Per Hour Missed_Break line on the matched rate sheet, else the claiming (or first Standard) Per Hour line times the Missed_Break pay code multipliers, Applied_Rule__c ending in Missed Meal Break Premium: First Meal Break, and no start/end times. Supplier and Bill lines are added only when the ruleset's Premium_Billable__c is true. See the pay and bill engine. Premium money rolls into Total_Pay__c / Total_Bill__c through the staging lines, but premium hours never touch the billable window, the overtime-hour rollups, or timesheet gross hours.
The Shift Rate Previewer shows the shift's break rows, the ruleset resolution trace and the capped premium hours (2 decimal places).
Break carving is side-aware: pay-side work blocks carve breaks that are not Is_Paid__c, bill-side blocks carve breaks that are not Is_Billable__c (a paid-but-not-billable rest break reduces the invoice but not the paycheck). The card's Breaks_Paid__c still disables carving on both sides. When the pay and bill sides carve different breaks, each side is priced, including overtime, independently. See the pay and bill engine reference.
// Regenerate: delete existing auto rows, insert fresh ones. Map keyed by shift Id.
Map<Id, b3s.BreakEngine.BreakResult> results = b3s.BreakEngine.run(shiftIds);
// Same result, no DML.
Map<Id, b3s.BreakEngine.BreakResult> preview = b3s.BreakEngine.simulate(shiftIds);
BreakResult: shiftId, breaks (list of BreakSpec: breakType, startTime, endTime, isPaid, isBillable, ruleId, ruleLabel, reason), trace (resolution steps), rulesetName, timeSource, timezoneName, error.
| Action | Purpose | Key args |
|---|---|---|
previewBreaks |
Simulate generation for one shift: zero DML. | shiftId, appType?, hostType?, sessionKey? |
generateBreaks |
Regenerate breaks for a set of shifts (synchronous DML). | shiftIds (list), appType?, hostType?, sessionKey? |
The caller needs access to b3s__Break__c and to every target shift; an unknown or inaccessible shift Id returns an ErrorResponse. Portal sessions may act only on shifts whose b3s__Contact__c is the signed-in contact. generateBreaks also rejects approval-locked shifts (Submitted/Approved) and requires create and delete on b3s__Break__c for authenticated users. previewBreaks performs no DML and stays available on locked shifts.
Object resp = b3s.GlobalRemotingRouter.callObject(
'b3s.BreakService',
JSON.serialize(new Map<String, Object>{
'endp' => 'previewBreaks',
'shiftId' => shiftId
})
);
Returns a SuccessResponse whose responseObject is a BreakResult (previewBreaks) or a map of shift Id to BreakResult (generateBreaks); failures return an ErrorResponse with the reason in message:
{
"statusCode": 200,
"success": true,
"statusType": "OK",
"responseObject": {
"shiftId": "a0X...",
"rulesetName": "US-CA California",
"timeSource": "Scheduled",
"timezoneName": "America/Los_Angeles",
"breaks": [
{
"breakType": "Meal",
"startTime": "2026-03-02T20:00:00.000Z",
"endTime": "2026-03-02T20:30:00.000Z",
"isPaid": false,
"isBillable": false,
"ruleLabel": "First Meal Break",
"reason": "Shift length 8h > 5h: First Meal Break (30 min) placed to end by hour 5"
}
],
"trace": [ { "level": "State", "matched": true, "detail": "Matched on State level: US-CA California" } ]
}
}
@AuraEnabled global static b3s.BreakEngine.BreakResult preview(Id shiftId) // zero DML
@AuraEnabled global static b3s.BreakEngine.BreakResult generate(Id shiftId) // persists
generate requires the caller to hold create + delete on b3s__Break__c and rejects approval-locked (Submitted/Approved) shifts with an AuraHandledException; preview performs no DML and carries no such gates.
The Shift Rate Previewer's break card is built on these. See the next section.
The shiftRatePreviewer native LWC (on the b3s__Shift__c record page) is the observability surface for both engines. Between the rate segments and the line breakdown it renders, from the simulate payload:
Break_Ruleset__c record, skipped levels showing the reason ("Shift site has no state value").Break__c: type, start and end in the shift's local time (timezoneName from the payload), duration in minutes, Paid/Unpaid and Billable badges, an Auto or Manual badge, and the source (b3s__Applied_Rule__c for auto rows, "Manual" otherwise). The whole section hides when the shift has no breaks and no level matched.premiumHours > 0; the premium lines themselves appear in the line breakdown tagged Premium.BreakService.generate(shiftId) (persisting regeneration) and reloads the preview, so an admin can see the effect of ruleset changes immediately.@InvocableMethod(label='Generate Shift Breaks' category='Workforce Management')
global static void generateBreaks(List<BreakService.Request> requests)
Request - b3s.BreakService.Request
| Variable | Type | Required | Notes |
|---|---|---|---|
shiftIds |
List<Id> |
yes | Shifts to regenerate breaks for. |
All requests are processed in one background job, 200 shifts at a time, so a bulk Flow run stays within platform limits. Requests with no shift Ids are skipped, and approval-locked shifts (Submitted/Approved) are left unchanged. The method returns nothing; generation is asynchronous. Use it from Flows that run as admins or trusted automation.
For rules that fields cannot express (New York's evening-meal span condition, headcount gates, industry carve-outs), implement BreakPlugin and name the class in Break_Ruleset__c.Plugin__c (ns.Class or a bare name; resolution is namespace aware, as for Apex filters). Plugins do placement only: no SOQL, no DML. Everything arrives in memory via the context; rounding, clamping, manual-coexistence suppression and DML remain the engine's job.
global with sharing class NyEveningMealPlugin implements b3s.BreakPlugin {
global List<b3s.BreakEngine.BreakSpec> compute(b3s.BreakEngine.BreakContext ctx) {
// ctx: shiftId, contactId, windowStart/windowEnd (from the ruleset's
// Time_Source), timezoneName, ruleset, rules (active, Priority ASC),
// existingManualBreaks (Is_Auto_Created__c = false)
List<b3s.BreakEngine.BreakSpec> specs = new List<b3s.BreakEngine.BreakSpec>();
// ... place breaks; set breakType, startTime, endTime, isPaid,
// isBillable, ruleId, ruleLabel, reason ...
return specs;
}
}
The packaged default placement (see Default placement) handles thresholds, tiers, recurrence and placement. Implement a plugin only for what your jurisdiction needs beyond it.
WFM_Admin permission set grants full access to Break_Ruleset__c, Break_Rule__c, Break_Setting__mdt and the break fields on Break__c and Shift__c. Grant other personas the access they need.BreakPlugin or a site-level override ruleset. Record waivers or attestations with Suppress_Break_Premiums__c.