QUESTION:
I have enabled Opportunities and a custom object for duplicate checking in DupeBlocker 3 and would like to add a list of the duplicates directly to the page layout, just like you can for the Account, Contact and Lead objects.
How can I accomplish this?
ANSWER:
This can be done by creating a custom Apex Class Controller and Visualforce Page. Once created, the Visualforce page can be added to the objects page layout in the same manner that the supplied Inline Duplicate List Pages are added for the standard objects (e.g. DupeBlocker - Account - Inline Duplicates List).
More information on adding an inline duplicates page for accounts, contacts, leads can be found here.
- Sample code for the Apex Class, Visualforce pages and unit tests 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.
- The "Opportunity" files are ready to use
- The "Test_Object__c" files will need to be customized for any other enabled DupeBlocker Objects.
NOTE: Code can be updated in notepad FIRST and then copied/pasted to the new Apex Controller, or code can be copied as is then modified after pasting and before saving.
******For Opportunities******
1. Create the Apex Class:
- Navigate to: Setup -> App Setup -> Develop -> Apex Classes -> New
- Paste the code from the Opportunity_Inline_Dupe_List_Controller.cls attached document and click save
2. Create the Visualforce Page:
- Navigate to: Setup -> App Setup -> Develop -> Pages -> New
- Label: Opportunity_Inline_Dupe_List
- Name: Will default to the same as above
- Paste the code from the Opportunity_Inline_Dupe_List.page attached document and click save
3. Create the Unit Test Class for the page and controller:
- Navigate to: Setup -> App Setup -> Develop -> Apex Classes -> New
- Paste the code from the Opportunity_Inline_Dupe_List_Tests.cls attached document and click save
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.
******For Other Non-Standard Enabled Objects******
1. Create the Apex Class:
- Navigate to: Setup -> App Setup -> Develop -> Apex Classes -> New
- Paste the code from the Test_Object_Inline_Dupe_List_Controller.cls attached document
- Change references to "Test_Object__c" to YOUR enabled object API Name (i.e. Location__c, Asset).
- Keep in mind that ONLY custom objects will have the __c at the end of the object name.
There will be 5 places that require updates (the comments in the code also point out where the changes need to be made):
- Line 1: public with sharing class Test_Object_Inline_Dupe_List_Controller
- __c (for custom objects) NOT NEEDED in this change
- ONLY replace the Test_Object portion, i.e. "Location_Inline_Dupe_List_Controller"
- Line 13: public Test_Object__c dupeRecord { get; set; }
- Line 18: this.dupeRecord = (Test_Object__c)dupeRecord;
- Line 31: public Test_Object_Inline_Dupe_List_Controller( ApexPages.StandardController stdController )
- __c (for custom objects) NOT NEEDED in this change
- ONLY replace the Test_Object portion, i.e. "Location_Inline_Dupe_List_Controller"
- Line 82: for ( sObject record : [SELECT Id, Name, OwnerId, Owner.Name FROM Test_Object__c WHERE Id IN :potDupes.keySet()]
- NOTE: This last statement can be modified to add additional fields for display in the duplicates list. If the object DOES NOT contain an owner field, the OwnerId and Owner.Name will need to be removed.
If, when attempting to save the class, a compile error is displayed indicating the name is too long, the name can be shortened to: Test_Object_IDL_Controller. This change will need to be made in Line 1 and Line 31 in the Apex Class. The Visualforce Page (instructions below) will need to be modified to use the shortened controller name also (for the Label, and Line 2 - extensions).
2. Create the Visualforce Page:
- Navigate to: Setup -> App Setup -> Develop -> Pages -> New
- Label: {Object_Name}_Inline_Dupe_List
- DO NOT include the __c for a custom object
- Should match the name specified at the top of the Apex Class, i.e. public with sharing class Location_Inline_Dupe_List_Controller
- Name: Will default to the same as above
- Paste the code from the Test_Object_Inline_Dupe_List.page attached document
- Change references to "Test_Object__c" to YOUR enabled object API Name (i.e. Location__c, Asset).
- Keep in mind that ONLY custom objects will have the __c at the end of the object name.
There will be 3 places that require updates:
- Line 1: 2 replacements
- <apex:page sidebar="false" standardController="Test_Object__c" extensions="Test_Object_Inline_Dupe_List_Controller">
- DO NOT include __c in the second replacements and ONLY replace the Test_Object portion, i.e. "Location_Inline_Dupe_List_Controller"
- Line 6: 1 replacement
- <apex:facet name="header">Test Object Name</apex:facet>
NOTE: If the object DOES NOT contain an owner field, then lines 9-12 will need to be removed:
<apex:column >
<apex:facet name="header">Owner</apex:facet>
<apex:outputText value="{!dupe.dupeRecord.Owner.Name}" />
</apex:column>
If other fields were selected in the controller, they can be added in, e.g.
<apex:column >
<apex:facet name="header">FieldA</apex:facet>
<apex:outputText value="{!dupe.dupeRecord.FieldA}" />
</apex:column>
Click Save
3. Create the Unit Test Class for the page and controller:
- Navigate to: Setup -> App Setup -> Develop -> Apex Classes -> New
- Paste the code from the Test_Object_Inline_Dupe_List_Tests.cls attached document
- Change references to "Test_Object__c" to YOUR enabled object API Name (i.e. Location__c, Asset).
- Keep in mind that ONLY custom objects will have the __c at the end of the object name.
- Modify any insert statements to create records for your custom object.
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.