Credential auto resolution

Credential auto resolution

When a client raises a shift or booking request in the Client Shift Manager, the Credentials step no longer starts empty. The system reads the Certificate Requirements configured for the account, job, job group, work site and work location behind the request, works out which of them apply, and writes them onto the request as locked credential rows. The client can add more credentials on top, but cannot edit or remove the ones the system derived.

This is the request side of the same rule the candidate side already runs when it scores a worker against a shift, so what a client is told to expect and what compliance later checks come from one configuration.

How it works

  1. The client completes the Details step. The request (Shift or Booking Request) is saved.
  2. Landing on the Credentials step resolves the requirements.
  3. The request is read with every field the configured criteria reference.
  4. The default rule checks the template Certificate Requirements: rows with no Shift and no Booking Request lookup, in other words the ones an administrator configured against an account, job, job group, site, location or cost centre.
  5. A template applies when every criterion it populates matches the request, and it populates at least one. A template with no criteria at all never applies.
  6. If the app definition names an Apex plugin, the plugin is called with the default matches and returns the final list.
  7. The resulting credentials are reconciled onto the request: missing rows are inserted with Is Auto Derived ticked, previously derived rows that no longer apply are deleted, and credentials the client added themselves are never touched.
  8. The step re-runs every time the credentials modal closes and every time the client returns to the step, so changing the job or site on the request updates the derived credentials.

Created on save, whatever the route

The wizard is not the only way a VMS request is created. A master vendor or administrator can use the standard New action on Shift or Booking Request, and requests also arrive from Flows, integrations and imports. So the same rule also runs from the Shift and Booking Request triggers:

When What happens
A Shift or Booking Request is inserted with VMS checked Its required credentials are derived and written as Is Auto Derived rows
VMS is switched on for an existing record Same
Any other edit (job, site, dates) Nothing. The wizard's Credentials step still reconciles on every visit

Details that matter when supporting it:

Switching the trigger off

Check Disable Credential Requirement Trigger (b3s__Scheduler__c.b3s__Disable_Credential_Requirement_Trigger__c) in Setup, Custom Settings, WFM Scheduler settings. It is a hierarchy setting, so it can be set for the org, a profile or a user (for example an integration user that writes its own requirement rows). The wizard's Credentials step is not affected.

Object model

Certificate Requirement records play two roles, distinguished by whether they point at a request:

Role Shift / Booking Request lookup Meaning
Template Empty Configuration: "any request for this account / job / site needs this credential"
Request credential Populated This request needs this credential

A new field supports the feature:

Field Type Purpose
Certificate_Requirement__c.Is_Auto_Derived__c Checkbox The row was created by the engine. Clients see it read only.

Grant read access to Is_Auto_Derived__c on any permission set used by internal or community users of the Client Shift Manager. Portal guest users do not need it. Version 11 does not grant Certificate Requirement object or field access through WFM Admin. Supply those permissions through an org-owned permission set.

Configuration

Everything lives in the schedulables.requirement block of the Client Shift Manager's Component Configuration. The definition maps the requirement and request fields.

"requirement": {
    "objectType": "b3s__Certificate_Requirement__c",
    "shiftFieldPath": "b3s__Shift__c",
    "bookingRequestFieldPath": "b3s__Booking_Request__c",
    "ticketTypeFieldPath": "b3s__Ticket_Type__c",
    "ticketTypeNameFieldPath": "b3s__Ticket_Type__r.Name",
    "autoDerivedFieldPath": "b3s__Is_Auto_Derived__c",
    "copyFields": [
        "b3s__Ticket_Type__c",
        "b3s__Priority__c",
        "b3s__Max_Award__c",
        "b3s__Max_Penalty__c"
    ],
    "accountFieldPaths": {
        "shift": ["b3s__Work_Job__r.b3s__Account__c", "b3s__Work_Site__r.b3s__Account__c"],
        "bookingRequest": ["b3s__Job__r.b3s__Account__c", "b3s__Site__r.b3s__Account__c"]
    },
    "criteria": {
        "shift": [
            {"requirementField": "b3s__Account__c", "recordField": "b3s__Work_Job__r.b3s__Account__c"},
            {"requirementField": "b3s__Job_Group__c", "recordField": "b3s__Work_Job__r.b3s__Job_Group__c"},
            {"requirementField": "b3s__Job__c", "recordField": "b3s__Work_Job__c"},
            {"requirementField": "b3s__Work_Site__c", "recordField": "b3s__Work_Site__c"},
            {"requirementField": "b3s__Work_Site_Location__c", "recordField": "b3s__Work_Site_Location__c"},
            {"requirementField": "b3s__Cost_Center__c", "recordField": "b3s__Cost_Center__c"}
        ],
        "bookingRequest": [
            {"requirementField": "b3s__Account__c", "recordField": "b3s__Job__r.b3s__Account__c"},
            {"requirementField": "b3s__Job_Group__c", "recordField": "b3s__Job__r.b3s__Job_Group__c"},
            {"requirementField": "b3s__Job__c", "recordField": "b3s__Job__c"},
            {"requirementField": "b3s__Work_Site__c", "recordField": "b3s__Site__c"},
            {"requirementField": "b3s__Work_Site_Location__c", "recordField": "b3s__Site_Location__c"}
        ]
    }
}
Key Required Purpose
autoDerivedFieldPath Yes Checkbox stamped on derived rows
criteria Yes Per request type, the pairs the default rule compares. requirementField is on the template, recordField is a field path on the request. Add a pair to bring another field into the rule.
accountFieldPaths Yes for portal Paths that resolve the request's client account. A portal session may only resolve requests belonging to the account of the contact in its session key. Leaving this out blocks portal sessions entirely.
copyFields No Fields copied from the template onto the derived row. The ticket type field is always copied.
apexPlugin No Class implementing the plugin interface, see below

Adding a criterion is the first thing to reach for when a client's rule needs another field: add the field to Certificate Requirement, add the matching field to Shift or Booking Request, and add one criteria entry.

Locking the derived rows in the UI

The Required Credentials related list on both request types gates editing on the flag, so no extra work is needed unless you build your own form:

"canEdit": {
    "condition": {
        "allOrSome": "all",
        "selectors": [
            {"operator": "notequals", "field": "b3s__Is_Auto_Derived__c", "value": true}
        ]
    }
}

canDelete carries the same condition. canCreate stays true so clients can still add their own.

Client specific rules with an Apex plugin

Where field equality is not enough - a rule that depends on shift length, a picklist on the account, a lookup two levels away, or a completely external source - name a class in apexPlugin:

"apexPlugin": "AcmeCredentialRule"

The class implements the packaged interface:

global class AcmeCredentialRule implements b3s.CertificateRequirementPlugin {
    public List<SObject> resolve(Map<String, Object> context) {
        List<SObject> defaults = (List<SObject>) context.get('defaults');
        String targetType = (String) context.get('targetType');
        SObject target = (SObject) context.get('targetRecord');
        // Add client-specific checks here, branching on targetType.
        // Query any extra fields needed using target.Id; only configured
        // criteria and account fields are guaranteed on targetRecord.
        return defaults;
    }
}

Context keys passed to resolve:

Key Type Notes
targetType String shift or bookingRequest
targetId Id The saved request
targetRecord SObject The request, carrying every criterion field
contactId String The signed in contact (for portal users, the contact the session key identifies)
defaults List<SObject> Templates the built in rule matched

The context deliberately does not carry every template in the org - there can be tens of thousands. A plugin that needs a wider net queries for it, filtered, itself.

Return the final list of template requirements to apply. Return defaults unchanged for a no op, or an empty list to suppress auto derivation entirely. Only the fields in copyFields are read from what you return, so rows built in memory are fine.

Use the bare class name for a class in an org without a namespace, or your own namespace and class name for a namespaced extension. Do not prefix subscriber classes with b3s. The name only ever comes from Custom Metadata, never from the browser.

Plugins run in their own sharing context. Declare without sharing if the plugin must return rows for portal guest sessions - a with sharing plugin sees nothing there.

Security

Scale

The design assumes an org can hold many thousands of Certificate Requirements and Ticket Types:

For large datasets, review the selectivity of any custom criteria and the number of matching templates returned.

Troubleshooting

Symptom Cause
No credentials appear No template Certificate Requirements match, or every template leaves all criteria empty
"Could not work out the required credentials" Check the debug logs: usually a criteria field path that does not exist on the request object, or a missing autoDerivedFieldPath
Portal client sees an invalid session error accountFieldPaths is missing from the requirement block, or the request does not belong to their account
A VMS request created from the record page has no credentials Disable Credential Requirement Trigger is checked, VMS was not checked when saving, no Client Shift Manager configuration exists, or the save held more than 5 requests and the background job has not finished
A derived credential can still be deleted The related list's canEdit / canDelete conditions are missing, or the user cannot read Is_Auto_Derived__c
Derived rows keep coming back after deletion Expected. The step reconciles on every visit. Remove the template requirement instead.

The console

Requirements are browsed, tested and maintained from the Credential Requirements tab in the 3B WFM and 3B VMS apps - see Credential requirements console.