Lesson 6 of 14 · All lessons

Section 3 · Process Automation and Logic · 28% of exam

3.2 Apex Types, Methods, Interfaces, and Control Flow

3 min read Updated Nov 16, 2026

Exam objective

Explain Apex variable and constant declarations, methods, modifiers, interfaces, and control-flow behavior, and apply them to a basic programmatic solution.

Read the shape of an Apex class

Apex is a strongly typed, object-oriented language integrated with Salesforce data and transactions. A class groups state and behavior; an object is an instance of a class. A method declares a return type, a name, and parameters, and may return a value to its caller. Use parameters to make dependencies explicit and return values to provide a clear result. A void method performs work without returning a value.

Variables hold values with a declared type, such as String, Integer, Date, a collection, or an sObject. A final variable cannot be reassigned after initialization and is useful for constants. Lists preserve order and may contain duplicates; sets store unique values; maps associate keys with values. In bulk Apex, collections let the code gather identifiers, query a group of records, and efficiently associate results.

Class and member modifiers define access and extension. private limits visibility to the class, public exposes members within the namespace, and global exposes a public API beyond the namespace where required. Use the narrowest appropriate scope. static attaches a member to the class rather than to each object instance. virtual permits a class or method to be extended, abstract declares an incomplete base class or method, and override provides a subclass implementation. An interface declares a contract that implementing classes must fulfill. Interfaces are useful when callers should depend on behavior rather than one concrete implementation.

Select control flow by meaning

Use if/else when a decision depends on Boolean conditions. switch can express multiple discrete branches. for iterates a known collection or range; while repeats while a condition remains true; do/while evaluates the condition after the first execution. break exits a loop or switch, and continue advances to the next loop iteration. A control-flow scenario asks what happens in sequence, so track variable changes and evaluate each condition in order.

Suppose a service processes a list of payment records and updates only those with a valid status. First identify the collection, then walk each record through the condition. A continue can skip an invalid item; a break would stop processing the remaining collection. Confusing them creates a common logic defect. For nested conditions, write a small truth table or trace with two or three representative records before choosing an answer.

Keep code small and testable

A method should have one clear responsibility and a name that describes its effect. Avoid methods with hidden dependencies on static mutable state or current UI state. When a requirement has multiple outcomes, return a typed result or use a clear exception model rather than relying on implicit side effects. Split methods when a single method mixes input validation, querying, business decisions, and user messaging.

Test access modifiers, inheritance, and interface behavior conceptually. If a caller must use one of several implementations, an interface may reduce coupling. If there is only one simple implementation and no extension need, adding inheritance can make the design harder to read. The exam focuses on selecting the appropriate mechanism for the scenario, not on applying every object-oriented feature.

When reading code, annotate each declaration with its type and scope, then trace method calls in order. For loops, write down the collection size and distinguish break from continue.

Extra concept: dependency inversion in a Salesforce service

A service can depend on an interface for an operation such as a pricing policy, while different implementations supply regional rules. This supports isolated tests and future variation. The pattern is helpful when meaningful alternatives exist; it is unnecessary ceremony for a one-line operation with no expected variation.

Key takeaways

  • Variables, constants, types, and collections express state; methods define clear input and output boundaries.
  • Access and definition modifiers control visibility and extension; interfaces express behavior contracts.
  • Trace condition evaluation and loop exits precisely, especially when a scenario compares `break`, `continue`, and branching.
  • Official references:
  • Salesforce Certified Platform Developer Exam Guide: https://help.salesforce.com/s/articleView?id=005298965&language=en_US&type=1
  • Writing Apex: https://developer.salesforce.com/docs/platform/apex-dev/references/apex-dev/apex-writing.html
  • Apex class definitions and modifiers: https://developer.salesforce.com/docs/platform/apex-dev/references/apex-dev/apex-classes-defining.html
  • Apex classes, objects, and interfaces: https://developer.salesforce.com/docs/platform/apex-dev/references/apex-dev/apex-writing.html
  • Apex control-flow statements: https://developer.salesforce.com/docs/platform/apex-dev/references/apex-dev/langcon-apex-control-flow.html

Check your knowledge

Answer exam-style Process Automation and Logic questions with answers and explanations.

Practice Process Automation and Logic
Finished this lesson? Mark it complete to track your progress.

Ready for the real exam?

Take the timed Salesforce Platform Developer simulator: same number of questions, same time limit.

Get Complete Access