Salesforce Dictionary - Free Salesforce GlossarySalesforce Dictionary
Full Visualforce Lifecycle entry
How-to guide

Reasoning about and debugging the Visualforce Lifecycle

Writing or debugging Visualforce pages requires understanding the lifecycle. The four-step routine for working with the Visualforce Lifecycle covers: read the lifecycle phases in the developer guide, write controllers that respect the phase order, debug lifecycle issues with the Developer Console, and migrate legacy pages to Lightning Web Components when the time is right. Each step is a different relationship with the lifecycle; mature Visualforce developers use all four together as the situation requires.

By Dipojjal Chakrabarti · Founder & Editor, Salesforce DictionaryLast updated May 19, 2026

Writing or debugging Visualforce pages requires understanding the lifecycle. The four-step routine for working with the Visualforce Lifecycle covers: read the lifecycle phases in the developer guide, write controllers that respect the phase order, debug lifecycle issues with the Developer Console, and migrate legacy pages to Lightning Web Components when the time is right. Each step is a different relationship with the lifecycle; mature Visualforce developers use all four together as the situation requires.

  1. Read the lifecycle phases in the developer guide

    Open the Salesforce Visualforce Developer Guide and read the Order of Execution section. The seven phases are documented with specific examples of what runs where. Reference this section every time you write a controller method, modify a getter, or add a new action handler. Without explicit knowledge of which phase fires when, controller code accumulates subtle bugs that manifest only under specific conditions (constructor running twice, setters firing in unexpected order, action methods triggering twice on rapid clicks). Bookmark the section; refer to it during every Visualforce code review.

  2. Write controllers that respect the phase order

    Put initialization logic in an init method called from the action attribute on the page tag, not in the constructor (the constructor runs on every POST as well as the initial GET). Cache expensive computation in instance variables; have getters return the cached value rather than recompute. Mark large collection variables as transient if they do not need to round-trip in view state. Use immediate=true on commandButtons that should skip validation (the immediate=true case is one of the few ways to alter the lifecycle order). Document the phase-respecting patterns in the team developer guidelines.

  3. Debug lifecycle issues with the Developer Console

    Open Developer Console and enable a debug log filter for the Visualforce user. Reproduce the bug. Inspect the log for the sequence of method calls; the debug log shows the controller constructor, every setter, every getter, every action method, and the view state size. Identify the deviation from expected lifecycle behavior. Common findings: a setter firing more than once because the page has two form fields bound to the same property; an action method not firing because the page actionRegion is misconfigured; view state exceeding 170 KB because a Wrapper class is holding too much data. Fix the issue and re-trace to confirm.

  4. Migrate legacy Visualforce pages to Lightning Web Components

    For each Visualforce page in production, evaluate whether migration to LWC adds value. High-traffic pages benefit most because the modern framework is more performant. Complex business logic in a Visualforce controller usually translates to a Lightning Web Component plus a supporting Apex controller class; the LWC handles the UI lifecycle and the Apex handles the server-side work. Lower-priority Visualforce pages can stay as-is. Document the migration backlog in the project tech debt registry. Plan migration during major Lightning Experience modernization projects rather than as standalone work.

Gotchas
  • The constructor runs on every POST, not just on initial page load. Initialization logic placed in the constructor runs more often than expected. Use the action attribute on the page tag for true one-time initialization.
  • View state is size-limited to roughly 170 KB. Large data sets in controller fields exceed the limit and produce a runtime error; use Transient or AJAX-only fetches for large data.
  • Expressions evaluate in document order, top to bottom. A getter inside an apex:repeat can fire hundreds of times; cache expensive computation in instance variables.
  • Action methods require a specific signature: no parameters, return PageReference or void. A signature mismatch silently fails to invoke; the platform does not raise an error, the method just does not fire.
  • Visualforce is in maintenance mode. New investment goes into Lightning Web Components; lifecycle expertise is increasingly a legacy skill for code maintenance rather than new development.

See the full Visualforce Lifecycle entry

Visualforce Lifecycle includes the definition, worked example, deep dive, related terms, and a quiz.