Performance18% of the exam

Code reuse with service layers, inheritance and modules

Where duplicated logic should live and which reuse mechanism fits: a bulkified, stateless service layer and selector classes in Apex, interfaces versus virtual and abstract inheritance, System.Callable across packages, LWC API module components, Visualforce templates and trigger-framework base classes.

Official exam objective
Identify scenarios where code reuse is applicable and how the reuse should be implemented.

~8 min read · 11 practice questions ·

What the exam expects

  • Recognize duplicated logic and move it to a service layer that LWC controllers, Queueable and Batch jobs, Apex REST resources and invocable actions all call.
  • Design service and selector methods that are bulkified, stateless, task-named and security-aware.
  • Choose an interface, a virtual class or an abstract class, and fix code that won't compile because the parent isn't extensible.
  • Call code in another package without a compile-time dependency using System.Callable.
  • Share client code between Lightning web components with an API module component, and share Visualforce layout with apex:composition.

Key terms: service layer (classes that encapsulate business tasks for many callers), selector (a class that centralizes queries, typically around one object), polymorphism (one call behaving differently depending on the object's class), template method pattern (a base class owns the flow and subclasses override hooks), API module component (an LWC folder whose main JavaScript file exports shared code).

Key facts

Single inheritance
Detail
Extend one class; implement many interfaces
override needs
Detail
A virtual (or abstract) parent class
Callable method
Detail
call(String action, Map<String, Object> args) returns Object
Service naming
Detail
General business terms, not a specific caller
Service state
Detail
Stateless; DML encapsulated in the service method
Service security
Detail
with sharing; elevate briefly when required
Selector benefit
Detail
Predictable minimum field set and one place for criteria
Invocable method
Detail
Static, public or global, outer class, one per class, at most one input
LWC library import
Detail
c/folderName main file only; re-export supplemental files
apex:include
Detail
Inserts an entire page; content can't vary
Sources for this section (8)
  • Why should an Apex service class be stateless?
  • When do you choose an interface over a base class?
  • Why does `class CsvExporter extends BaseExporter` fail when `BaseExporter` has no modifier?
  • Which file of an LWC library can other components import?
  • When is `apex:composition` better than `apex:include`?

The questions are free to read. Answers with their sources and self-grading are included with the pack.

Keep reading with the Platform Developer II pack

  • Core concepts
  • Exam traps
  • Worked scenario

The pack includes:

  • All 28 lessons of the Platform Developer II guide, with reading progress
  • Interactive decision walks and step-by-step sequence steppers
  • Inline practice questions and one-click topic practice (11 questions for this lesson)
  • An official source cited for every claim
  • An AI tutor that answers from the guide
  • Unlimited timed practice exams

Practice for the Platform Developer II exam