Skip to content

Commit

Permalink
Updates
Browse files Browse the repository at this point in the history
  • Loading branch information
Kyle Schmid committed Jan 12, 2018
1 parent 02d27a3 commit c7381df
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 8 deletions.
Binary file added Example_Duplicate_Report.xlsx
Binary file not shown.
16 changes: 12 additions & 4 deletions README.md
Expand Up @@ -12,9 +12,9 @@ Object Merge is released under the open source BSD license. Contributions (code


### Unmangaged Package ### Unmangaged Package


You can go to one of the following URLs to install Object Merge as an unmanaged package: You can go to one of the following links to install Object Merge as an unmanaged package:
* Production: https://login.salesforce.com/packaging/installPackage.apexp?p0=04t0H0000019nSt * <a href="https://login.salesforce.com/packaging/installPackage.apexp?p0=04t0H0000019npT" target="_blank" >Production</a>
* Sandbox: https://test.salesforce.com/packaging/installPackage.apexp?p0=04t0H0000019nSt * <a href="https://test.salesforce.com/packaging/installPackage.apexp?p0=04t0H0000019npT" target="_blank" >Sandbox</a>


### Ant/Force.com Migration Tool ### Ant/Force.com Migration Tool
You can fork this repository and deploy the unmanaged version of the code into a Salesforce org of your choice. You can fork this repository and deploy the unmanaged version of the code into a Salesforce org of your choice.
Expand Down Expand Up @@ -103,7 +103,15 @@ Once installed, you'll want to set up your first Object Merge Handler. To do so,


## Typical Use Cases ## Typical Use Cases


* While this tool doesn't identify duplicates, Salesforce has great standard features for doing so. You can run a report to get duplicate IDs and then use data loader with the Object Merge Pair object to merge duplicates en masse. * While this tool doesn't identify duplicates, Salesforce has great standard features for doing so. You can run a report to get duplicate IDs and then use Data Loader with the Object Merge Pair object to merge duplicates en masse:
* Sort by Duplicate Record Set Name then in a manner to make your master records show up first
* Add columns for Master ID and Victim ID
* Copy the first ID to the Master ID field
* Use the Excel formulas in Example_Duplicate_Report.xlsx for the rest of the Master ID and Victim ID rows
* Copy/paste the Master ID and Victim ID columns into a new spreadsheet
* Sort by Victim ID and remove all rows with blank Victim IDs
* Save as a .csv
* Use Data Loader to insert these pairs into the Object Merge Pair object
* If you'd like to provide a more intuitive UI for your users to merge certain types of objects, you can leverage custom lookup fields, workflow field updates, and record types to remove the need for users to copy and paste Salesforce IDs. Example for Contact: * If you'd like to provide a more intuitive UI for your users to merge certain types of objects, you can leverage custom lookup fields, workflow field updates, and record types to remove the need for users to copy and paste Salesforce IDs. Example for Contact:
* Create "Master Contact" and "Victim Contact" lookups * Create "Master Contact" and "Victim Contact" lookups
* Create a "Contact Merge Pair" Page Layout * Create a "Contact Merge Pair" Page Layout
Expand Down
6 changes: 3 additions & 3 deletions src/classes/ObjectMergePairTriggerHandler.cls
Expand Up @@ -53,11 +53,11 @@ public class ObjectMergePairTriggerHandler {
if (Id.valueOf(p.Master_ID__c).getSobjectType() != Id.valueOf(p.Victim_ID__c).getSobjectType()) if (Id.valueOf(p.Master_ID__c).getSobjectType() != Id.valueOf(p.Victim_ID__c).getSobjectType())
throw new ObjectMergePairException(); throw new ObjectMergePairException();


prefixes.add(String.valueOf(Id.valueOf(p.Master_ID__c)).substring(0, 3));

} catch (Exception e) { } catch (Exception e) {
addError(p, 'Invalid Master/Victim ID pair'); addError(p, 'Invalid Master/Victim ID pair');
} }

prefixes.add(String.valueOf(Id.valueOf(p.Master_ID__c)).substring(0, 3));
} }


// Get prefix-name map // Get prefix-name map
Expand Down Expand Up @@ -119,7 +119,7 @@ public class ObjectMergePairTriggerHandler {
} }
} }


// Method to perform merge of a list of pairs of the same object type // Method to perform merge of a list of pairs of the same object type
private static void doMerge(List<Object_Merge_Pair__c> pairs, Object_Merge_Handler__c handler, Map<Id, List<Object_Merge_Field__c>> fields, Map<Id, List<Object_Merge_Field__c>> matchingFields) { private static void doMerge(List<Object_Merge_Pair__c> pairs, Object_Merge_Handler__c handler, Map<Id, List<Object_Merge_Field__c>> fields, Map<Id, List<Object_Merge_Field__c>> matchingFields) {


// Get set of parent record ids // Get set of parent record ids
Expand Down
25 changes: 24 additions & 1 deletion src/classes/ObjectMergePairTriggerHandlerTest.cls
Expand Up @@ -342,6 +342,28 @@ private class ObjectMergePairTriggerHandlerTest {
System.assertEquals('Error performing DML', p1.Error_Reason__c); System.assertEquals('Error performing DML', p1.Error_Reason__c);
} }


@isTest
static void test_errors_4() {

Object_Merge_Pair__c p1 = new Object_Merge_Pair__c(Master_ID__c = 'test', Victim_ID__c = 'test');
Object_Merge_Pair__c p2 = new Object_Merge_Pair__c(Master_ID__c = 'test', Victim_ID__c = 'test');
insert new List<Object_Merge_Pair__c>{p1, p2};

p1.Status__c = 'Retry';
p1.Master_ID__c = p2.Id;
p1.Victim_ID__c = p1.Id;

Test.startTest();

update p1;

Test.stopTest();

p1 = [SELECT Id, Error_Reason__c FROM Object_Merge_Pair__c WHERE Id = :p1.Id];

System.assertEquals('Error performing DML', p1.Error_Reason__c);
}

@testSetup @testSetup
static void setup() { static void setup() {


Expand All @@ -360,7 +382,8 @@ private class ObjectMergePairTriggerHandlerTest {
Object_Merge_Handler__c h1 = new Object_Merge_Handler__c(Name = 'Account', Active__c = true, RecordTypeId = pId); Object_Merge_Handler__c h1 = new Object_Merge_Handler__c(Name = 'Account', Active__c = true, RecordTypeId = pId);
insert h1; insert h1;
Object_Merge_Handler__c h2 = new Object_Merge_Handler__c(Name = 'Contact', Active__c = true, Standard_Action__c = 'Delete Victim', RecordTypeId = cId, Child_Relationship_Name__c = 'Contacts', Object_Lookup_Field_API_Name__c = 'AccountId', Parent_Handler__c = h1.Id); Object_Merge_Handler__c h2 = new Object_Merge_Handler__c(Name = 'Contact', Active__c = true, Standard_Action__c = 'Delete Victim', RecordTypeId = cId, Child_Relationship_Name__c = 'Contacts', Object_Lookup_Field_API_Name__c = 'AccountId', Parent_Handler__c = h1.Id);
insert h2; Object_Merge_Handler__c h3 = new Object_Merge_Handler__c(Name = 'Object_Merge_Pair__c', RecordTypeId = pId);
insert new List<Object_Merge_Handler__c>{h2, h3};


Object_Merge_Field__c f1 = new Object_Merge_Field__c(Name = 'Name', Use_for_Matching__c = false, Object_Merge_Handler__c = h1.Id, Active__c = true); Object_Merge_Field__c f1 = new Object_Merge_Field__c(Name = 'Name', Use_for_Matching__c = false, Object_Merge_Handler__c = h1.Id, Active__c = true);
Object_Merge_Field__c f2 = new Object_Merge_Field__c(Name = 'Website', Use_for_Matching__c = false, Object_Merge_Handler__c = h1.Id, Active__c = true); Object_Merge_Field__c f2 = new Object_Merge_Field__c(Name = 'Website', Use_for_Matching__c = false, Object_Merge_Handler__c = h1.Id, Active__c = true);
Expand Down

0 comments on commit c7381df

Please sign in to comment.