---
schema_version: "1"
id: 77fe325337a3e8615f3b7b9306be6b20da75e57d083bae4d18548774c9ad87d5
title: Write Efficient Getter Methods
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/platform/salesforce-pages-developers-guide/guides/pages/best-practices/best-practices-performance/pages-best-practices-perf-getters.md
canonical_url: https://developer.salesforce.com/docs/platform/salesforce-pages-developers-guide/guide/pages-best-practices-perf-getters.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: ea882aa8ae024100839aba12963c651610ef95511d861f683cf5e8a289404971
products:
  - Visualforce Developer Guide
  - Platform Developer Content
---

# Write Efficient Getter Methods

Visualforce requests evaluate expressions, action attributes, and other method calls. A request such as a form submission can call the getter methods in a class multiple times. With more efficient getter methods, you can prevent unnecessary lookups of the same record.

To reduce the processing load of each request, cache the value of a property calculation so that additional calls can access the property without recalculating the value.

You can also configure the getter methods in your Apex classes to only query for data if the object is null. For example, the following code snippet returns the Account record associated with the page. On the first method call, the method queries for the record because the MyAccount object is null. On subsequent calls, it returns the object’s stored value, which prevents additional identical `SELECT` queries:

```apex

 Account MyAccount;
 public Account getMyAccount() {
    if (MyAccount == null) {
            MyAccount = [SELECT name, annualRevenue FROM Account
            WHERE
            id = :ApexPages.currentPage().getParameters().
            get('id')];
        }
    return MyAccount;
 }

```

**See Also**  


-   [Defining Getter Methods](https://developer.salesforce.com/docs/platform/quick-start/advanced/pages-quick-start-controller-getter-methods.md)

