Javatpoint Logo
Javatpoint Logo

<apex: page> Component in Visualforce Page

It is a standard Visualforce component which is very important in Visualforce because each and every page starts with this component. All the other Visualforce components must be wrapped inside the <apex: page> component.

It supports HTML pass-through attributes using the "html-" prefix. The pass-through attributes are attached to the generated <html> tag.

Let's take an example to understand how we can use this component.

ApexPageExample.vfp

Output

apex: page component in Visualforce Page

Attributes

The <apex: page> component of Visualforce provides the following attributes:

1. action

The type of action attribute is ApexPages.Action. The action method is invoked when the page is requested by the server. In order to define the action method, we use expression language for referencing the method.

Syntax:

Here, "{!doAction}" references the doAction() method in the controller.

The action attribute is an optional attribute, so if we don't specify it, the page loads as usual. If the doAction() method returns null, the page simply refreshes.

The action method invokes after invoking the constructor of the controller class or before rendering the page. The action attribute allows us to optionally redirect to another page.

Note: In the action method, we don't use initialization or DML.

2. apiVersion

The type of the apiVersion attribute is double. The apiVersion attribute is used to define the version of the API used for rendering and executing the page.

Syntax:

3. applyBodyTag

The type of the applyBodyTag attribute is Boolean, which is used to specify whether Visualforce automatically adds a <body> tag to the generated HTML output or not. We will set applyBodyTag to false to disable adding the <body> tag to the response, for example, when the <body> tag is statically set in your markup. If not specified, this value defaults to the value of the applyHtmlTag attribute if it's set or true if applyHtmlTag isn't set

Syntax:

4. applyHtmlTag

The applyHtmlTag is also a Boolean type of attribute that is used to specify whether Visualforce automatically adds a <html> tag to the generated HTML output. Set to false to disable adding the <html> tag to the response, for example, when the <html> tag is statically set in your markup. If not specified, this value defaults to true.

Syntax:

5. cache

It is another Boolean type of attribute that is used to specify whether the browser caches this page or not. If we set it to true, the browser will cache this page; else, not. If the cache attribute is not specified, by default assumes its value to be false.

However, by default, the value of the cache attribute is true for all Force.com Sites pages.

If we set the attribute value to true for Hyperforce customers, it allows us to use Salesforce Edge-enabled global caching.

Syntax:

6. contentType

The contentType is a String type attribute that is used for formatting the rendered page. The value of the contentType attribute can be one of the following:

  1. text/html
  2. text/csv
  3. image/png
  4. image/gif
  5. video/mpeg
  6. text/css
  7. audio/basic

We can set the filename of the rendered page by appending to the MIME type a "#", followed by the file name.

Syntax:

Note: Dynamically switching the content type from an HTML to a non-HTML type such as text/csv or image/png isn't supported.

7. controller

It is a String type attribute that is used to specify the Apex class for controlling the behavior of this page. We cannot use the controller attribute when the standardController is already in use.

Syntax:

8. cspHeader

The cspHeader attribute is another Boolean type attribute that indicates whether this page uses CSP(Content Security Policy) or not for imposing restrictions on content. If we set its value to true, browsers make requests from the page to an external server only when the server is defined as CSPTrustedSite with a context of VF or All.

Syntax:

9. deferLastCommandUnityReady

It is a Boolean attribute that is used to specify whether we need to prevent premature clicking of command buttons and links or not. By default, its value is false, and when we set it to true, the last click on a button or link is enqueued and processed when the page is ready.

Syntax:

10. docType

The docType attribute is used to specify the different doctype for a VF page. By default, VF pages are served with a doctype of HTML 4.01 Transitional.

In order to create a VF page with an XHTML 1.0 Strict document type, we add the docType attribute in the following way:

Syntax:

11. expires

The "expires" attribute is an Integer type attribute that is used to define the expiration period for the cache attribute in seconds. If the "expires" attribute is not defined and the cache attribute is set to true, the default value of the "expires" attribute is 0.

However, the default value of the "expires" attribute is set to 600 seconds for the Force.com Sites pages when the cache is not set to false.

Syntax:

12. extensions

If we want to use the custom controller with standardController, we use the extensions attribute. We can add more than one custom controller extension to add additional logic for this page.

Syntax:

13. id

It is one of the most important attributes that is used to allow this page to be referenced by other components on the page.

Syntax:

14. label

The label attribute is used for referencing this page in Salesforce setup tools.

Syntax:

15. language

The language attribute is used for displaying labels having associated translations in Salesforce. The value defines in the language attribute overrides the language of the user viewing the page.

Syntax:

16. lightningStylesheets

Another important Boolean type attribute that is used for controlling the style of the Visualforce page when it is viewed in Lightning Experience. If this attribute is set to true and the page is viewed in Lightning Experience, Lightning Experience style sheets are applied to the page.

If this attribute is not specified or set to false, the classic style sheets are always used.

Note: If standardStylesheets and lightningStylesheets are both used, the lightningStylesheets attribute overrides the standardStylesheets attribute.

Syntax:

17. manifest

It is used for adding a manifest attribute for the generated <html> tag that references a cache manifest file for offline use.

Syntax:

18. name

The name attribute is used to define the unique name for referencing the page in the Lightning Platform API.

Syntax:

19. pageStyle

This attribute was deprecated in Salesforce API version 16.0.

20. readOnly

The readOnly attribute is used to enable the read-only mode for a VF page. The page can't execute any DML operations when the read-only mode is enabled.

Syntax:

21. recordSetName

This attribute was depreciated in Salesforce API version 16.0.

22. recordSetVar

This attribute indicates that the page uses a set-oriented standard controller. The value of the attribute indicates the name of the set of records passed to the page. This record set can be used in expressions to return values for display on the page or to perform actions on the set of records.

Syntax:

23. renderAs

The name of any supported content converter. Currently, PDF is the only supported content converter. Setting this attribute to "pdf" renders the page as a PDF.

Syntax:

24. rendered

It is another Boolean-type attribute that specifies whether the page is rendered or not. By default, its value is set to true.

Syntax:

25. setup

It is a Boolean attribute that specifies whether the page uses the style of a standard Salesforce setup page. If this attribute is not specified, its value defaults to false.

Syntax:

26. showChat

A Boolean attribute that specifies whether the Chatter Messenger chat widget is included in the page or not.

Syntax:

27. showHeader

It is a Boolean attribute that is used for specifying whether the Salesforce tab header will be included on the page or not. It's by default value is true.

Syntax:

28. showQuickActionVfHeader

It is a Boolean attribute that is used for specifying whether the header of the quick action that calls this page needs to be displayed or not. It's by default value is true.

Syntax:

<apex:page showQuickActionVfHeader="true"></apex:page>

29. sidebar

It is a Boolean attribute that is used for specifying whether the standard Salesforce sidebar is included in the page or not. Its default value is false.

Syntax:

30. standardController

It is of type String that defines the Salesforce object for controlling the behavior of the page.

Syntax:

31. standardStylesheets

A Boolean attribute is used for applying the Salesforce standard style sheet to the page header that is generated when the showHeader is set to false. By default, its value is set to true.

Syntax:

32. tabStyle

Another attribute of type String that defines the Salesforce object or custom Visualforce tab for controlling the color, selected tab, and styling for this page. For the custom object, the tabStyle attribute should be specified with the developer name for the object.

Syntax:

33. title

Another attribute of type String that is responsible for generating HTML<title> element inside the VF page.

Syntax:

34. wizard

Another Boolean attribute that is responsible for applying the style of the standard Salesforce wizard page. By default, its value is set to false.

Syntax:







Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA