Loading
Prepare for Email to Become the Default Login ExperienceRead More
Energy & Utilities Cloud
Write the Apex Services for Template Flows

Write the Apex Services for Template Flows

Support the emergency callout template flows by writing three Apex classes. Each class implements an @InvocableMethod that a flow action binds to by class name, method label, and variable labels, so keep those elements exactly as documented.

Required Editions

Available in: Lightning Experience
Available in: Enterprise, Performance, and Unlimited editions with Energy & Utilities - Growth, Field Service for Energy & Utilities, and Contractors for Energy & Utilities
User Permissions Needed
To create Apex: Author Apex

Get Workforce Availability

For a new resource callout record, the EmergencyCallOutCandidateService class determines how many technicians are available in each pay grade. The class creates one resource callout requirement record per pay grade. The class:

  • Resolves the callout's service appointment to its service territory.
  • Groups active, technician-type service territory members by pay grade.
  • Calls the Field Service FSL.GradeSlotsService.getGradedMatrix() method to check availability against the given scheduling policy.
  • Creates one requirement record per pay grade with the total and available resource counts.
  • Sets IsRequirementGenerated to true on the resource callout record when it finishes.

The action takes a required callout ID and a required scheduling policy name, and returns a success flag and a message. Validate both inputs synchronously, and resolve the policy name to an ID up front so a bad policy name surfaces immediately. When the Field Service works in an @future(callout=true) method, and check IsRequirementGenerated first so a retry doesn't regenerate requirements. Apply field-level security and object security on every write (for example, with Security.stripInaccessible()), even though the class runs without sharing.

Generate Emergency Callout Roster

For a callout whose requirements now have a required quantity, the EmergencyCallOutRosterService class builds a ranked roster of candidate technicians. The class:

  • Reads requirements for the callout that aren't yet rostered and have a required quantity greater than zero.
  • Multiplies each required quantity by a roster multiplier to shortlist more candidates than strictly needed.
  • Ranks technicians in the territory by their highest FSL.SchedulingOption.Grade, and creates resource callout assignment records up to the adjusted quantity, using the grade as the fitment score.
  • Sets each processed requirement's IsCallOutRosterGenerated to true when it finishes.

The action takes a required callout ID, an optional scheduling policy name (defaults to Emergency), and a roster multiplier (defaults to 5.0), and returns a success flag and a message. Have the class re-query the requirements it needs from the callout ID directly, rather than relying on requirements passed in from the flow.

Rank Emergency Callout Resources

When a dispatcher opens the Add Resource modals by ranking view for a specific resource callout requirement, the EmergencyCallOutRankedCandidateService class returns the eligible technicians for that requirement's pay grade, ranked by Field Service scheduling grade. The class:

  • Resolves the callout's service appointment to its service territory.
  • Reads the pay grade from the requirement whose Add Resource button was clicked, and collects active, technician-type service territory members who hold that pay grade.
  • Calls the Field Service FSL.GradeSlotsService.getGradedMatrix() method to get each resource's highest scheduling grade.
  • Ranks the candidates in descending order by grade, assigns a rank of 1 through N, and returns the ranked list as a single JSON string for the flow to pass to the component.

The action takes a required callout ID, a required callout requirement ID, and an optional scheduling policy name (defaults to Emergency), and returns a success flag, a message, and a ranked resources JSON string. Each element in the JSON array carries the resource ID, name, pay grade name, territory name, rank, and grade.

To keep ranks consistent with the roster, rank over the same candidate list that the roster uses for that pay grade, and apply the same deterministic tie-break (grade descending, then name, then ID).

 
Loading
Salesforce Help | Article