Friday, November 29, 2013

Salesforce: Modify default View in Object Tab

By default, when user click an object tab in Salesforce, example: Account tab, user will be presented with latest View selected by login user, example in screenshot below, it show "My Accounts" view, this mean, user select "My Accounts" before open an Account or click anywhere else. After View is Recent Accounts list.

Note: list of accounts when user click this Account tab is NOT "My Accounts" view, but it is Recent Accounts, until user click Go! button next to View name or select another View.

But, can we modify the default view when user click the tab? 

YES, using Visualforce page. Don't be afraid, you not really need to understand the whole Visualforce page script and Apex code, just copy from script below :) 

1. Always show a View
You can start create visualforce page from Setup - Develop - Pages, click New button, enter the label and name, then copy and paste script below
    <apex:enhancedList listId="00B500000063yvG" height="600" customizable="true" rowsPerPage="10"/>

  • listId : the Salesforce object for which views are displayed. This value is required if type is not specified. From above example: you can grab this View Id from URL when open a View, sample: this is always 15 characters
  • height : an integer value that specifies the height of the list in pixels. This value is required.
  • customizable : a Boolean value that specifies whether the list can be customized by the current user. If not specified, the default value is true. If this attribute is set to false, the current user will not be able to edit the list definition or change the list name, filter criteria, columns displayed, column order, or visibility, however, the current user's personal preferences can still be set, such as column width or sort order. If this attribute is set to true, user will see Edit | Delete | Create New View links. 
  • rowsPerPage : an integer value that specifies the number of rows per page. Possible values are 10, 25, 50, 100, 200. Note: If you set the value for greater than 100, a message is automatically displayed to the user, warning of the potential for performance degradation.

2. Always show "Recently Viewed Objects"
<apex:page showHeader="true" tabstyle="Opportunity"> 
    <apex:ListViews type="Opportunity" /> 

Okay, so we can customize the tab using simple Visualforce page, next question, how to put it on? Two option:

1. Overwrite existing standard tab
  • Setup - Account (for Account object) - Buttons, Links, and Actions
  • Look for Accounts Tab (just change the object name for other object)
  • Click Edit link 
  • Select Visualforce Page option then page you create above
  • Save
To note: once you overwrite the tab with visualforce, default Quick Access Menu at the middle right of the page of View page will be no longer available.

2. Create new tab
  • Setup - Create - Tabs
  • Go to Visualforce Tabs 
  • Click New button
  • Select Visualforce page you create above
  • Follow the wizard and Save

Loop back: how to modify columns in Recent Object view?


No comments:

Post a Comment

Page-level ad