QUESTION:
I would like to customize the redirect text and/or add fields in the pop-up list that appears in the upper right when multiple matches are found. How can I accomplish this?
ANSWER:
This is accomplished with a custom Visualforce redirection page.
The default redirect Controller and Visualforce page that ships with the application cannot be modified as they are part of the managed package.
DupeBlocker 3 has a match on insert action, Redirect to Visualforce Page, that allows a custom Visualforce redirection page to be used when a duplicate is found.
This is similar to the standard Redirect to Existing action except that with a custom page the redirect text (that is shown in the middle of the screen) can be customized and/or additional fields can be added to the pop-up when multiple matches are found.
How To:
- Sample code for the custom Apex Class and Visualforce pages are attached (file extension .cls is the class code, and file extension .page is the Visualforce page code).
- The files can be opened in either Notepad or Notepad++ and the code can then be copied and pasted directly into the Salesforce User Interface.
1. Create the Apex Class:
- Navigate to: Setup -> App Setup -> Develop -> Apex Classes -> New
- Paste the code from the CustomContactRedirectController.cls attached document
- Update the SOQL select statement on Line 40 to include all the desired fields (or remove fields).
- The following example shows the select modified to also include the Account.Name and Owner.Name for the Contact object:
- dupes = [SELECT Id, Name, Account.Name, Owner.Name FROM Contact WHERE Id IN :dupeIds];
- The following example shows the select modified to also include the Account.Name and Owner.Name for the Contact object:
2. Create the Visualforce Page:
- Navigate to: Setup -> App Setup -> Develop -> Pages -> New
- Label: CustomContactRedirect
- Name: Will default to the same as above
There are 3 areas that can be customized in the page:
a. Customize the redirect text displayed in the middle of the screen
- Lines 28 & 29: Update text as desired
<FONT> You have been redirected to this page because a duplicate record was detected.<BR />
<BR /> If more than one possible duplicate was found, they are displayed in the upper right corner. </FONT><BR />
b. Customize the fields displayed in the pop-up box (upper right)
- Line 51: Fields can be added (or removed) by updating the output between the apex:outputLink tags (currently {!dupe.Name}) to display the desired fields
<apex:outputLink target="displayFrame" onclick="setRedirectByIndex('{!dupe.Id}')" value="/{!dupe.Id}">{!dupe.Name} at {!dupe.Account.Name} Owner: {!dupe.Owner.Name}</apex:outputLink><BR/>
Example Output: Jon Smith at ABC Co. Owner: Amy Johnson
c. Customize the size of the redirect box
- If adding additional fields to display the size of the pop-up box may need to be adjusted to minimize text wrapping
- Line 12: Adjust height
- Line 13: Adjust width
Example with width increased from 25em to 40em:
height: 6em;
width: 40em;
NOTE: Typically, only the width needs to be adjusted but may adjust the height also as the dupe list could be lengthy.
This example is for Contacts, but the attached files can be updated for any object. See comments in the custom classes/pages for where and how to modify for other objects.
Controller:
Line 1: Controller Name
Line 8: Object Name (add __c for custom objects)
Line 17: Controller Name
Line 40: Object Name (add __c for custom objects)
Line 48: Object Name (add __c for custom objects)
Page:
Line 1: Controller Name
NOTE: Enable Apex Class Access for desired non admin user profiles. Setup -> Develop -> Apex Class, locate the created class, click security and add profiles. The custom Visualforce page will also need to be enabled for any non admin Salesforce profiles.[attach]19,20[/attach]