Requested Documents

From 3B Knowledge
Jump to navigation Jump to search

What's new in Version 9

The Document Assignment (b3o__Document_Assignment__c) now shows live counts of the documents requested from the contact, so admins and flows can see onboarding progress at a glance without opening the portal.

New fields on Document Assignment

Field Type Meaning
Requested Documents (b3o__Requested_Documents__c) Number How many documents of the pack are currently visible/required from the contact (after evaluating each document's conditional rendering rule).
Submitted Documents (b3o__Submitted_Documents__c) Number Requested documents with at least one submission.
Completed Documents (b3o__Completed_Documents__c) Number Requested documents whose latest submission is Approved and not expired.
Outstanding Documents (b3o__Outstanding_Documents__c) Formula (Number) Requested - Submitted.
All Documents Submitted (b3o__All_Documents_Submitted__c) Formula (Checkbox) True when at least one document is requested and all are submitted.
All Documents Completed (b3o__All_Documents_Completed__c) Formula (Checkbox) True when at least one document is requested and all are completed.

The checkbox formulas are ideal entry criteria for flows and reports (e.g. "notify recruiter when all documents are completed").

How it works

  • A new object, Requested Document (b3o__Requested_Document__c), materialises which documents of the pack are actually requested from each contact — one record per (Document Assignment, Document) pair. It stores b3o__Is_Required_From_Contact__c, b3o__Is_Submitted__c, b3o__Is_Completed__c and b3o__Latest_Submission__c.
  • When a Document Assignment is created, Requested Documents are calculated automatically in the background (asynchronously — allow a short delay before counts appear).
  • When a Document Submission is created or updated, the matching Requested Document and the counts update immediately.
  • Document visibility can also change due to external factors (contact field changes, certificate expiry, other submissions). Recalculation for those cases is admin-controlled — see Recalculating on demand below.

Data migration switch

b3o__Onboarding_Trigger_Control__c.b3o__Disable_Requested_Documents_Trigger__c (hierarchy custom setting) bypasses the automatic creation/sync triggers during data loads. Run the backfill batch afterwards (below). The count rollup itself is never bypassed.


Post-install: backfill existing Document Assignments

Document Assignments created before this version have no Requested Documents and their counts are blank. Backfill them once after installing/upgrading:

  1. Open Developer Console → Debug → Open Execute Anonymous Window (or use sf apex run).
  2. Run:
Database.executeBatch(new b3o.RequestedDocsRecalcBatch(
    'SELECT Id FROM b3o__Document_Assignment__c'
), 5);

Notes:

  • You provide the SOQL, so you can scope the backfill however you like. The query may return either b3o__Document_Assignment__c or Contact records (contacts are resolved to their assignments automatically):
// Only assignments for contacts still onboarding
Database.executeBatch(new b3o.RequestedDocsRecalcBatch(
    'SELECT Id FROM Contact WHERE Onboarding_Status__c = \'In Progress\''
), 5);
  • Keep the batch scope small (5–10). Each document with a conditional rendering rule costs SOQL queries proportional to the rule's conditions; a large scope can hit governor limits.
  • The batch is idempotent — safe to re-run at any time.
  • Monitor progress under Setup → Apex Jobs. Errors are logged via the package's standard error handling.

Recalculating on demand (Flow / Apex)

Because document visibility can depend on data outside the pack (contact fields, certificate expiry dates, etc.), you decide when to recalculate. The package exposes an invocable action:

Action: 3B Recalculate Requested Documents (category: 3B Onboarding)

Input: Assignment Ids — a list of b3o__Document_Assignment__c record Ids.

From Flow

  1. In Flow Builder, add an Action element and search for 3B Recalculate Requested Documents.
  2. Pass the Document Assignment Id(s) into Assignment Ids (a text collection of record Ids, or a single record Id resource).
  3. Typical wiring:
    • Record-Triggered Flow on Contact — when a field used in rendering rules changes, pass the Ids of the contact's Document Assignments (Get Records on b3o__Document_Assignment__c where b3o__Contact__c = the contact).
    • Screen Flow / quick action on Document Assignment — pass recordId for a manual "Recalculate" button.

The action returns immediately; the recalculation runs asynchronously in the background (it self-chains for large packs). Counts update within moments.

From Apex

b3o.RequestedDocumentsHelper.recalculate(new Set<Id>{ assignmentId });

Safe to call from triggers and from already-async contexts (falls back to inline processing when no queueable slots remain).

When to trigger a recalculation

  • A contact field referenced by any document's conditional rendering rule changes.
  • A certificate/credential referenced by a rule is added, updated, or expires.
  • You changed the documents or rules in a Document Pack and want existing assignees re-evaluated (for many assignments, use the batch above instead).

All recalculation paths are idempotent — running them twice is harmless.