Skip to content

ProjectReferral routing, access and alerts

  • Industry

    Healthcare

  • Cloud

    Apex, LWC, Flow

  • Role

    Lead developer

What this project covers

Triggers that react to record updates, batch classes, validation, wrapper classes for LWCs, email logic, Permission Sets, Flows and custom sharing — all in one requirement. Each layer has its own page with the code and the reasoning.

The requirement

A hospital network receives patient referrals from clinics and routes each one to a regional coordination team.

As a referral coordinator, I want every referral for my region to appear on my board the moment it is routed, with the urgent ones announced, so that I triage the right patients first and never see another region’s patients.

Acceptance criteria:

  1. A referral with a Region is assigned to the least-loaded active coordinator of that region. Changing the region reassigns it. Reopening a closed referral reassigns it too.
  2. Referrals are private by default. Only the owner, the regional coordinator group and the assigned coordinator can open one, and nobody sees a region that is not theirs.
  3. When the region changes, the previous region’s access is revoked in the same transaction. When a referral closes, the regional group drops from Edit to Read.
  4. A referral cannot be declined without a reason, and cannot leave New without a region.
  5. When a referral becomes Urgent, the assigned coordinator gets a bell notification and an email.
  6. The coordinator’s board (an LWC) lists their open referrals, shows which ones they can edit, and lets them mark a referral as triaged without a page reload.
  7. All of it survives a bulk load of 200 referrals in one transaction, and a nightly job can recalculate access if group membership or routing configuration changed.

Data model

ArchitectureObjects and relationships
Standard objectsReferral objectsAccess and configurationPatient__cReferring_Clinic__cAssigned_Coordinator__cmaster-detailParentIdUserOrGroupIdCoordinator_Group__cContactthe patientAccountreferring clinicUsercoordinatorReferral__cOWD: PrivateReferral_Note__cmaster-detail childReferral__ShareApex sharing reasonsPublic groupone per regionReferral_Routing__mdtregion to group

Referral__c carries Region__c, Status__c (New, Triaged, Scheduled, Completed, Declined), Priority__c (Urgent, Routine) and Routed_On__c.

Architecture

ArchitectureOne transaction, from save to notification
ExperienceApex layersData and accessDeclarativewirebeforeafterinsert / deletethenreferralBoardLWCReferralBoardControllerwrapper classesReferralTriggerdispatches onlyReferralTriggerHandlerbefore / afterRoutingServiceassigns coordinatorSharingServicegrants and revokesSelectorsSOQL lives hereReferral__ShareUrgent referral flowafter saveBell and emailto the coordinator

The batch class that recalculates access (see Record access) calls the same SharingService, so there is one definition of who should see what.

Who can do what

Access is configuration, so it ships as Permission Sets and not as profile edits.

Persona Permission set Gets
Intake agent Referral_Intake Create and edit Referral__c they own, read Contact and Account
Coordinator Referral_Coordinator Read and edit Referral__c shared with them, create Referral_Note__c, the Urgent_Referral notification type
Admin none needed Manages the groups, the routing metadata and the Flow

The pages

  • Triggers: one trigger per object, a handler framework, change detection, a recursion guard, and the routing rule.
  • SOQL: selector classes, relationship and aggregate queries, WITH USER_MODE, and the SOQL-in-a-loop mistake.
  • LWC wrappers: the DTO classes, a cacheable method, error handling and the LWC that uses them.
  • Record access: Apex managed sharing, the __Share object, revoking stale access and the recalculation batch.
  • Flows and notifications: the record-triggered Flow, the same behaviour in Apex, and when to pick which.
  • Tests: a data factory, a 200-record test and access assertions with System.runAs.

Built with the Salesforce Lightning Design System. Not affiliated with Salesforce.

App Launcher