Power Line Scheduling with Visualforce and Apex

Introduction

Salesforce Field Service Lightning (FSL) is widely used in utilities and energy organizations to manage power line inspections, fault repairs, and preventive maintenance. Behind the scenes, powerful Salesforce ORM (Object Relational Mapping) features—combined with Visualforce and Apex—enable teams to build custom scheduling, dispatch, and work management experiences on top of standard Field Service objects.

In this article, we explore how Salesforce’s ORM model is practically implemented in a Power Line Scheduler use case, using:

  • Work Orders
  • Service Appointments
  • Service Resources (line workers)
  • Visualforce pages
  • Apex controllers

Salesforce ORM in the Context of Field Service

Salesforce does not expose ORM in the same way as Hibernate or Entity Framework. Instead, sObjects + SOQL + DML form a tightly integrated ORM layer.

In Field Service, key ORM entities include:

Business Concept Salesforce Object
Power Line Job WorkOrder
Scheduled Visit ServiceAppointment
Field Technician ServiceResource
Crew Assignment AssignedResource
Location ServiceTerritory

Each table is an sObject, each row is an instance, and relationships are navigated directly through Apex.


Use Case: Power Line Maintenance Scheduler

Business Scenario

A utility company performs routine power line inspections. Dispatchers need:

  • A list of open Work Orders
  • Visibility into scheduled Service Appointments
  • Ability to assign or reassign line technicians
  • A custom UI optimized for dispatch workflows

While Field Service provides the standard Gantt Scheduler, some organizations build custom Visualforce scheduling consoles for special planning scenarios or legacy integrations.


ORM Entity Relationships

The core relationships in this use case look like this:

WorkOrder
   └── ServiceAppointment
          └── AssignedResource
                 └── ServiceResource
Salesforce ORM lets us traverse these relationships naturally in SOQL.
Querying Power Line Work Orders (SOQL ORM)

List<WorkOrder> powerLineJobs = [
    SELECT Id, WorkOrderNumber, Status, Priority,
           (SELECT Id, AppointmentNumber, Status, SchedStartTime, SchedEndTime
            FROM ServiceAppointments)
    FROM WorkOrder
    WHERE Status IN (‘New’, ‘In Progress’)
    AND RecordType.DeveloperName = ‘Power_Line_Maintenance’
];

✅ ORM advantages here:

  • Parent–child relationship query
  • Automatically returns typed WorkOrder and ServiceAppointment records
  • No manual joins or mapping logic required

Visualforce as an ORM-Aware UI Layer

Visualforce binds directly to sObjects retrieved by Apex controllers. This allows dispatchers to interact with live Field Service data.

Custom Scheduler Page

<apex:page controller=”PowerLineSchedulerCtrl”>
    <apex:form>
        <apex:pageBlock title=”Power Line Scheduler”>
            <apex:pageBlockTable value=”{!workOrders}” var=”wo”>
                <apex:column value=”{!wo.WorkOrderNumber}” />
                <apex:column value=”{!wo.Status}” />

 

                <apex:column headerValue=”Appointments”>
                    <apex:repeat value=”{!wo.ServiceAppointments}” var=”sa”>
                        <div>
                            {!sa.AppointmentNumber}
                            ({!sa.SchedStartTime} – {!sa.SchedEndTime})
                        </div>
                    </apex:repeat>
                </apex:column>
            </apex:pageBlockTable>
        </apex:pageBlock>
    </apex:form>
</apex:page>

Visualforce understands the ORM metadata and renders:

  • Date/time fields correctly
  • Related data without manual joins
  • Record permissions automatically (when using with sharing)

Apex Controller: Power Line Scheduler

public with sharing class PowerLineSchedulerCtrl {
public List<WorkOrder> workOrders { get; private set; }

 

    public PowerLineSchedulerCtrl() {
        workOrders = [
            SELECT Id, WorkOrderNumber, Status,
                   (SELECT Id, AppointmentNumber, Status,
                           SchedStartTime, SchedEndTime
                    FROM ServiceAppointments)
            FROM WorkOrder
            WHERE Status != ‘Closed’
            ORDER BY CreatedDate DESC
            LIMIT 50
        ];
    }
}

Why this is ORM-driven

  • WorkOrder is treated as a domain object, not a table
  • Relationship navigation is object-based
  • Strong typing reduces runtime errors
  • Salesforce automatically enforces security and validation

 

Assigning Line Technicians (ORM + DML)

When a dispatcher assigns a technician, the system creates an AssignedResource record.

AssignedResource ar = new AssignedResource(
    ServiceAppointmentId = appointmentId,
    ServiceResourceId = technicianId
);
insert ar;

What Salesforce ORM handles automatically:

  • Foreign key integrity
  • Trigger execution
  • Resource availability recalculation
  • Field Service optimization rules

Validation, Triggers, and Transactions

When saving scheduling changes:

  • Validation rules ensure no overlapping appointments
  • Triggers enforce safety compliance
  • Scheduling policies re-evaluate feasibility
  • Entire transaction is rolled back if any step fails
Savepoint sp = Database.setSavepoint();
try {
    insert ar;
} catch (Exception e) {
    Database.rollback(sp);
    throw e;
}
This transactional consistency is a key advantage of Salesforce’s ORM model.

Security and Sharing in Field Service

All controller logic uses:

public with sharing class PowerLineSchedulerCtrl

This ensures:

  • Dispatchers only see territories they are allowed to manage
  • Technicians cannot view schedules outside their region
  • Object and field-level security is enforced automatically in Visualforce

Why Use Visualforce in Field Service?

While Lightning Web Components are dominant today, Visualforce is still used when:

  • Embedding custom schedulers in legacy consoles
  • Supporting hybrid Service Cloud + Field Service setups
  • Rapidly building metadata-driven UIs
  • Leveraging Standard Controllers for CRUD actions

Visualforce’s tight coupling with the Salesforce ORM makes it especially effective for administrative and dispatcher-facing tools.


Key Takeaways

✅ Salesforce ORM in Field Service:

  • Maps real-world power line operations directly to sObjects
  • Eliminates the need for manual persistence logic
  • Enforces security, validation, and transactions automatically

✅ Visualforce enhances ORM by:

  • Binding UI components directly to field service data
  • Reducing boilerplate code
  • Accelerating custom scheduler development

✅ For utility and energy companies:

  • Custom Field Service schedulers can be safely built
  • Power line maintenance workflows stay scalable and secure
  • Salesforce becomes a true operational platform—not just CRM