No Results
Search Tips:
- Please consider misspellings
- Try different search keywords
Newer Version Available
Using Salesforce Styles
- When you use a standard controller with a Visualforce page, your new page takes on the style of the associated object’s standard tab in Salesforce. It also allows you to access the methods and records associated with the associated object.
- When you use a custom controller, the tabStyle attribute of an <apex:page> tag allows you to mimic the look and feel of the associated Salesforce page. If you only want portions of the page to be similar to a Salesforce page, you can use the tabStyle attribute on the <apex:pageBlock> tag. For an example, see Defining Getter Methods.
Extending Salesforce Styles
Use the <apex:stylesheet> tag to add additional stylesheets to a page. Use the style or styleClass attribute available on most Visualforce components to connect them to style definitions in your stylesheets. This technique lets you extend the Salesforce styles with your own.
The following markup shows a very basic page. The <apex:stylesheet> tag references a CSS stylesheet that is saved as a static resource named TestStyles under Setup, in . It’s referenced by the $Resource global variable in the <apex:stylesheet> tag’s value attribute. The styleClass attribute of the <apex:outputText> tag uses the sample style class defined in the style sheet.
This is the style sheet used for this example:
Identifying the Salesforce Style Your Users See
When you’re creating a Visualforce page, it’s often useful to know the Salesforce look and feel your user expects, in order to render a page that matches their style. For example, some users have the choice to customize their look and feel. You’ll need to design your Visualforce pages to take these differences into consideration.
There are two global variables that can help you identify which style a user sees: $User.UITheme and $User.UIThemeDisplayed. The difference between the two variables is that $User.UITheme returns the look and feel the user is supposed to see, while $User.UIThemeDisplayed returns the look and feel the user actually sees. For example, a user may have the permissions to see the new user interface theme look and feel, but if they are using a browser that doesn’t support that look and feel, for example, Internet Explorer 6, $User.UIThemeDisplayed returns a different value.
- Theme1—Obsolete Salesforce theme
- Theme2—Salesforce theme used prior to Spring ’10
- PortalDefault—Salesforce Customer Portal theme
- Webstore—Salesforce AppExchange theme
- Theme3—Current Salesforce theme, introduced during Spring ’10
- Using the rendered attribute you can “toggle” which sections display.
- Since the <apex:stylesheet> tag doesn't have a rendered attribute, you'll need to wrap it in a component that does.
Using the Salesforce Stylesheets
Salesforce uses different stylesheets (.css files) throughout the application to ensure that every tab conforms to the Salesforce look and feel. These stylesheets are automatically included on a Visualforce page unless you specify false for the showHeader attribute of the <apex:page> tag.
When you disable the inclusion of the Salesforce stylesheets, only your custom stylesheets will affect the styling of the page. For the purposes of building up styles that partially or fully match the Salesforce look and feel, you might want to look at and use selected contents from the default stylesheets.
- dStandard.css – Contains the majority of style definitions for standard objects and tabs.
- allCustom.css – Contains style definitions for custom tabs.