Strategic business units (SBU)

A strategic business unit (SBU) is a division of your organisation, for example Healthcare, Industrial or Education. Multi-division agencies and master vendors use SBUs to:

Every org has at least one SBU, the default SBU, created automatically on install or upgrade. An org with one unit needs nothing else: the default SBU is simply where the invoice number series and the invoice letterhead live.

Objects

Object Purpose
SBU (b3s__SBU__c) One record per business unit. Holds the code, the active and default flags, the legal entity details and the two number series. Tab: SBUs in the 3B WFM and 3B VMS apps. Sharing: Public Read Only.
SBU Assignment (b3s__SBU_Assignment__c) Links one Account, Contact or User to an SBU. Accounts, workers and users can belong to several units. Exactly one of Account, Contact and User must be set (validation rule Exactly_One_Target); duplicates are refused through the unique Key__c (target Id + SBU Id, stamped automatically). Is_Primary__c marks the main unit.

SBU fields

Field Use
Name, Code__c Display name and a short unique code (for reports and integrations).
Active__c Inactive units are no longer stamped on new records and are not offered in pickers.
Is_Default__c Exactly one active unit is the default. Making another unit the default clears the previous one; the only default cannot be unticked.
Disable_Pay_Bill_Estimates__c Opts the unit's shifts out of automatic pay/bill estimates while the global switch is on.
Legal_Name__c, Trading_Name__c, Street__c, City__c, Province_State__c, Postal_Code__c, Country__c Legal entity name and address printed on invoices. Blank legal name = the SBU name.
Company_Registration_Number__c, Tax_Registration_Number__c Printed on invoices; the tax number is also passed to tax plugins.
Invoice_Email__c, Invoice_Phone__c Contact details printed under the address.
Bank_Details__c Payment instructions printed on client invoices (never on self-bills). Restrict its field-level security to finance users.
Logo_Document_Id__c ContentVersion (068...) or ContentDocument (069...) Id of the logo printed on the invoice header.
Payment_Terms_Days__c Due date offset used when the invoice configuration has no payment terms.
Invoice_Prefix__c, Last_Invoice_Number__c Client invoice and client credit note series.
Self_Bill_Prefix__c, Self_Bill_Last_Number__c Self-bill and self-bill credit note series.
Number_Padding__c Minimum digits after the prefix, zero-padded. 6 gives INV-000042; blank or 0 gives INV-42.
Group_Id__c Read only. The unit's public group, created automatically in SBU mode (see Record visibility).

Prefixes are unique across every unit and both series (case-insensitive).

SBU lookups on other objects

Object Field How it is set
Job SBU__c By you. Required while SBU mode is on (validation rule SBU_Required_In_SBU_Mode). A job belongs to exactly one unit.
Account, Contact SBU__c (primary unit) Kept in sync with the primary SBU Assignment in both directions: setting the field creates or promotes that unit's assignment; making an assignment primary writes the field.
Shift, Working Pattern, Booking Request, Expense SBU__c Stamped automatically while SBU mode is on (see below).
Pay/Bill Staging SBU__c Copied from the shift when the line is created. Corrections keep the original line's unit.
Pay/Bill Run SBU__c The unit a run was limited to; blank = every unit.
Invoice SBU__c Stamped at generate. Decides the number series and the PDF letterhead. Frozen once the invoice is numbered.
Invoice Configuration SBU__c Optional unit scope of a configuration (see Invoice configuration per unit).

SBU mode

Tagging and filtering are switched on by the WFM custom setting field SBU Mode (b3s__Scheduler__c.b3s__SBU_Mode__c, Setup > Custom Settings > WFM > Manage). It is off by default.

SBU mode off SBU mode on
Work record stamping None Shift, Working Pattern, Booking Request, Expense
Job SBU Optional Required
Invoice split Kind, bill-to, currency (+ category) Plus SBU: one document never mixes units
Invoice SBU The default SBU The lines' unit (blank lines: the default SBU)
:sbuIds clause token Unrestricted The running user's units
Pay/Bill Runner, Invoice Generator, Studio No SBU picker or filter SBU picker / sbu filter

Turning the mode on does not re-stamp existing records by itself. New and edited records are stamped from then on. Records already interpreted by the pay and bill engine are not back-filled on a plain save (the shift lock would refuse the change). Run the back-fill batch once to stamp and share existing data.

How a record gets its unit

Shift, Working Pattern and Booking Request, first match wins:

  1. The job's SBU.
  2. The job account's primary SBU.
  3. Booking Request only: the requisition account's (b3s__Account__c) primary SBU.
  4. The site account's primary SBU. Sites carry no SBU: one site can host several units at the same client, and the job decides.
  5. The default SBU.

Expenses: the expense's shift unit, else its placement's unit (stamped, else derived as above), else the worker's primary SBU, else the default SBU.

The unit is computed on insert and whenever it is blank. On update it is recomputed only when the job or site (expense: shift, placement or worker) changes. A unit set explicitly in the same save wins.

Changing a job's unit later keeps historical records on the unit they were worked under. Only the job's future, unworked shifts move to the new unit: scheduled start in the future, no actual start time, blank approval status and not yet interpreted. The Job trigger starts SbuRestampBatch for this automatically. Working patterns, booking requests and expenses of the job keep their unit.

Filtering by unit

Pay/Bill Runner

In SBU mode the runner shows an SBU picker (default: All SBUs). A run limited to a unit interprets only shifts whose b3s__SBU__c is that unit, stores the unit on the run (Pay_Bill_Run__c.SBU__c, shown next to the period in the run list) and reverses over the same unit. Re-run keeps the original run's unit. Pick one unit per run; start one run per unit for a multi-unit payroll.

Invoice Generator

On an App or Home page in SBU mode the bulk run offers an SBUs checkbox group (none ticked = every unit) and the invoice list shows an SBU column. A bulk run processes each client one unit at a time: only that unit's uninvoiced lines are invoiced, only that unit's un-numbered drafts are replaced, and the configuration is resolved per unit.

On an Account page, Generate invoices every unit of the account with the selected configuration; the SBU split key still produces one invoice per unit.

Shift Management Studio

In SBU mode the Studio header search always offers an SBU filter (shiftPath and expensePath b3s__SBU__c), also on a custom Shift Management Studio configuration that does not list it. It starts pre-selected with the user's own SBU assignments; remove the pills to see every unit. The shift table shows the unit under Job / Site. To add the filter explicitly (for example with another label), add it to the configuration JSON:

"headerFilters": [
  { "key": "sbu", "label": "Business unit", "shiftPath": "b3s__SBU__c", "expensePath": "b3s__SBU__c" }
]

Loaders and portal clauses

Two clause tokens are available in loader filterRecordsBy and schedulable selectionClause (see Loaders):

Token Resolves to
:sbuIds The running user's units from their User SBU Assignments, as ('id1','id2'). Unrestricted when SBU mode is off or the user has no assignment: every active SBU plus blank, so b3s__SBU__c IN :sbuIds is always safe.
:userSbuId The user's primary unit as a quoted Id, or '' when none.
{ "name": "unitShifts", "objectName": "b3s__Shift__c",
  "filterRecordsBy": "b3s__SBU__c IN :sbuIds AND b3s__Status__c != 'Cancelled'" }

Portal guests and community users have no User assignments, so the token does not narrow their results. Portal sessions are scoped by access profiles and :accountIds. Portals never expose the unit structure: b3s__SBU__c and b3s__SBU_Assignment__c are not available to portal sessions.

Shift matching rule

The sample compliance rule Scheduler: SBU Match (b3s__Scheduling_Compliance_Rule.WFM_Scheduler_SBU_Match, unpackaged sample) warns, without blocking, when a worker is not assigned to the shift's unit. Cross-unit redeployment stays possible but visible. It needs a scheduler loader named sbuAssignments and b3s__SBU__c among the shift schedulable's field paths:

{ "name": "sbuAssignments", "objectName": "b3s__SBU_Assignment__c",
  "fieldToLoad": "b3s__SBU__c, b3s__Contact__c", "groupRecordsBy": "b3s__Contact__c",
  "filterRecordsBy": "b3s__Contact__c != null" }

Record visibility

With SBU mode on and the WFM custom setting field SBU Sharing Enabled (b3s__Scheduler__c.b3s__SBU_Sharing_Enabled__c, off by default) ticked, the package maintains sharing so that users of a unit can be limited to that unit's records. The sharing only restricts anything once you set the organisation-wide default (OWD) of the objects to Private; until then every user still sees every record, as before.

Leave SBU Sharing Enabled unticked when you need SBUs only for tagging, filters, number series, legal entities and invoicing, with no change to who sees what. No groups, group members or share rows are written then, and the back-fill batch only stamps units and creates primary assignments. Ticking it later and running the back-fill batch writes the groups and shares for existing records. Unticking it stops further share maintenance but does not remove rows already written; delete the SBU groups (Setup > Public Groups, names starting SBU_) to remove their access.

What the package maintains

Record Shared with How
Shift, Job, Expense The group of the record's SBU__c Share row with the Apex sharing reason SBU, Read/Write. Moves when the unit changes. Kept on owner change.
Site The groups of every unit the site's account is assigned to Share rows with the SBU reason. Follows the account's SBU Assignments and a change of the site's account.
Booking Request The group of its SBU__c Same as Shift, but only once the object has a sharing table (see the admin steps).
Account The groups of every unit in its SBU Assignments Manual AccountShare rows, Read/Write on the account, no opportunity or case access. Written only while the Account OWD is Private or Public Read Only. Re-created after an owner change, because Salesforce deletes manual shares when the owner changes.
Contact The groups of every unit in its SBU Assignments Manual ContactShare rows, same rules as Account. Written only while the Contact OWD is Private or Public Read Only, never while it is Controlled by Parent. The package does not depend on Contact sharing, so it installs in orgs where Contact is Controlled by Parent.
Working Pattern, Cost Center Controlled by parent: nothing to maintain.

Each unit has a public group named SBU_<SBU record Id> (label "SBU" + the unit name), created when the SBU is saved in SBU mode and stored in Group_Id__c. Its members are the users of the unit's User SBU Assignments. Adding or removing a User assignment updates the membership a few seconds later (an asynchronous job, because group membership is setup data). A user with several assignments is in several groups and sees the union.

Only rows granted to SBU groups are ever changed. Your own manual shares and sharing rules are untouched.

Role hierarchy still applies: managers above a group member see what the member sees. Profiles and permission sets with View All or Modify All on an object still see everything on it.

Portals

Portal and kiosk sessions are unchanged. Portal sessions are scoped by access profiles and :accountIds. The SBU and SBU Assignment objects stay hidden from portal sessions.

Turning visibility on

  1. Turn on SBU Mode and SBU Sharing Enabled, and create the SBUs (the default SBU exists already).
  2. Add User SBU Assignments for every internal user who should be limited to units. Users with no assignment see nothing of the restricted objects once the OWD is Private, unless the role hierarchy or a View All permission gives it to them.
  3. Run the back-fill batch once (below) and wait for every step to finish (Setup > Apex Jobs).
  4. In Setup > Sharing Settings, set the Default Internal Access to Private on Shift, Job, Site and Expense. Salesforce recalculates sharing; this can take a while on large orgs.
  5. Booking Request: its default external access is Public Read/Write, so it has no sharing table and the package cannot write its rows yet. Set its Default External Access and Default Internal Access to Private, then re-run the back-fill batch so existing booking requests get their rows. Until you do, booking requests stay visible to everyone.
  6. Optional: set Account to Private to limit clients by unit. Set Contact to Private only if workers should be isolated by unit (off by default: with Contact Controlled by Parent, workers follow their account). Re-run the back-fill batch after changing either, because manual shares are only written while the OWD allows them.

The package cannot change OWD on install or upgrade. An org that never changes it keeps today's visibility.

Back-fill batch

Run from Setup > Developer Console > Execute Anonymous:

Database.executeBatch(new b3s.SbuBackfillBatch(), 200);

It does nothing while SBU mode is off. Otherwise it chains one run per object (Job, Account, Contact, Site, Shift, Working Pattern, Booking Request, Expense, Invoice, Pay/Bill Staging) and:

Interpreted shifts, approved expenses and numbered invoices are stamped too: the batch writes only the unit, bypassing the payroll and invoice locks. It is safe to run again.

Restamp batch

SbuRestampBatch re-stamps a job's future unworked shifts after the job's unit changes (see How a record gets its unit). The Job trigger starts it. A job changed from a batch or scheduled job does not start it; run it by hand with the job Ids:

Database.executeBatch(new b3s.SbuRestampBatch(new Set<Id>{ 'a0X...' }), 200);

Invoice numbering

Invoice numbers come from the invoice's SBU (blank = the default SBU):

Issuing locks the units involved and increments the counter, so concurrent issues never reuse a number. With one unit this gives one global series per document kind; with several units each entity has its own.

When the unit has no prefix for the kind, the legacy series applies: the configuration's Invoice_Prefix__c / Last_Invoice_Number__c for client invoices, the vendor account's Self_Bill_Prefix__c / Self_Bill_Last_Number__c for self-bills. These fields remain available for intentional per-configuration or per-vendor numbering. Leave the unit's prefix blank for the relevant kind to use them; a populated unit prefix takes precedence over both the fallback prefix and counter. Client and self-bill choices are independent. Only the selected counter advances, so review the destination counter before switching series. See Issuing and numbering for setup and examples.

Upgrade and install

On every install and upgrade, when no SBU exists, a default SBU is created from Company Information (name, address) with code DEFAULT:

The step never fails the install. If the org already has SBUs but none is the default, nothing is created: tick Default on one of them.

After upgrading, review the default SBU: fill in the legal name, tax and company registration numbers, bank details and logo, and set Number_Padding__c if your numbers should be fixed-width. If several configurations used different prefixes, decide which prefix the unit series should carry.

Invoice split and stamp

In SBU mode the unit joins the implicit split keys (kind, bill-to, currency, category and SBU), so each invoice belongs to one unit and therefore one number series and one letterhead. The invoice's SBU__c is stamped at generate. Credit notes carry the unit of the invoice they credit. With the mode off, every invoice is stamped with the default SBU.

Turning SBU mode on changes the split key of new drafts. With the Amend Existing correction mode, new lines no longer join invoices issued before the switch; they go on new invoices.

Invoice configuration per unit

An invoice configuration can be scoped to a unit with SBU__c. When a bulk run invoices a client's lines of one unit, the configuration is resolved in this order:

  1. The client's active configurations for that unit.
  2. The client's active configurations with no unit.
  3. The active default configurations for that unit (Is_Default__c, no Account).
  4. The active default configurations with no unit.

PDF letterhead

The shipped Default template (InvoicePdf page) prints the SBU as "this organisation" when the invoice has a unit:

Without a unit, the org's Company Information is used, as before. Custom templates can read the same properties from the InvoicePdfController (supplier, customer, logoUrl, bankDetails).

Tax plugins

InvoiceTaxRequest carries sbu (name, legal name, tax registration number, country, province/state) so a custom InvoiceTaxPlugin can apply the issuing entity's own registration and rates. The default plugin ignores it.

Payment terms

Due date = issue date + the configuration's Payment_Terms_Days__c, else the SBU's Payment_Terms_Days__c, else 0.

Payroll

Every pay staging line carries the shift's unit, so a payroll export can group by it. Separate legal entities run separate payrolls; the recommended grouping for a payroll export is the worker's primary unit (the employer, Contact.SBU__c) with the shift unit on each line for intercompany recharge.

Setting it up

  1. Open the SBUs tab. Review the default SBU created on install and add one record per business unit with a unique code. Fill in the legal entity fields and the number series of each unit that issues its own invoices.
  2. Assign units: set SBU on each Job; set the primary SBU on client accounts and workers (or add SBU Assignment rows for several units); add User assignments for internal users so the Studio and :sbuIds default to their units.
  3. Optionally scope invoice configurations to a unit.
  4. Tick SBU Mode in the WFM custom setting.
  5. Give finance users access: the WFM Admin permission set grants read and edit on the SBU and SBU Assignment objects and fields; restrict Bank_Details__c field-level security as needed.
  6. Optional: limit record visibility by unit (see Turning visibility on).

Limits