6

This question already has an answer here:

Currently I am trying to prevent contacts with the matching first and last names from being assigned to the same Account. Currently on contact I have an custom Account Id field on contact that's updated via a workflow rule.

My active matching rule looks like the following:

(Contact: Account_Id EXACT MatchBlank = FALSE) AND (Contact: FirstName EXACT MatchBlank = FALSE) AND (Contact: LastName EXACT MatchBlank = FALSE)

My duplicate rule has the following settings:

  • Bypass sharing
  • Block on update
  • Block on edit
  • No conditions
  • Active
  • The matching rule mentioned earlier

I'm unsure of why it's not blocking the creation. At first I thought it was because (according to documentation) workflow rules trigger after Duplication rule checks are made but I ensured those fields were populated and tested it again.

For example:

We have John Smith assigned to Generic LLC. I should be able to add Alex Smith, John Brown, Alex Brown, etc. But I shouldn't be able to add another John Smith to Generic LLC. I should be able to add John Smith to Other Company Inc. but there can't be two contacts with the same first and last name assigned to one account.

Note: When using the Contact object for matching rules this is an example of what the options will look like.

Duplicate Management look

Currently the only issue I'm experiencing is if I create an account that has the same first and last name as an inactive account and is associated with the same account the new contact is not blocked. New / updated Active Contact with existing duplicate Active contact does block.

As suggested I have created a trigger that looks like the following:

trigger ContactTrigger on Contact (after delete, after insert, after undelete, 
after update, before delete, before insert, before update) {
    if(Trigger.isBefore && !Trigger.isDelete){
        for(Contact c : trigger.new){
            if(c.RecordTypeId == RecordTypes__c.getValues('Inactive Contacts').Id__c){
                c.Account_Id__c= c.AccountMap__c;
            }
            else{c.Account_Id__c = c.AccountId;}
        }
    }
}

AccountMap is the same thing as AccountId but it's done in a custom field so Inactive contacts don't show up on the account page.

Trouble shooting tip: Sometimes turning off and on duplicate rules fixes things.

marked as duplicate by Vigneshwaran G, Sebastian Kessel, crmprogdev, Adam Spriggs, cropredy Jul 27 '16 at 0:05

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 2
    So you're wanting to disallow a contact with same first & last name but unique contactId's and accountId's from being assigned to the same Account? If being assigned to the same account, at the time of assignment, the AccountId's would presumably be unique from one another until after the update occurred wouldn't they? Perhaps you could provide a specific case example (with values) of what you're trying to prevent? – crmprogdev Jul 20 '16 at 17:45
  • 1
    @crmprogdev Added an example. Hope that helps. – Griffin Jul 20 '16 at 18:25
  • 2
    Where does the field Account_Id come from? Is that on Contact? it's not Contact.AccountId is it? – crmprogdev Jul 20 '16 at 18:37
  • 1
    @crmprogdev Account_Id__c is a custom field on contact – Griffin Jul 22 '16 at 17:16
  • 1
    @Griffin How is the Account_Id__c field populated? Why not just use the Contact.AccountId? – Fernando Gavinho Jul 25 '16 at 10:55
2
+50

What you're asking is possible, but not the way you're trying. I see only one option:

  • Instead of a workflow, use a before trigger to make the change on the Account_Id field.

Also, mind that duplicate rules are only evaluated if the watched fields are evaluated, and that can cause trouble on the testing as well.

  • This was one of my first ideas but it was shot down by product owner, QA, and other devs really fast because Account name isn't always unique. If account name holds the Id instead of the actual name i will accept this. I'm not sure how to test this however – Griffin Jul 25 '16 at 13:24
  • If you go to Setup > Customize > Contact > Fields you'll see that the Account Name has the API name Account and is a reference (Lookup) to Account. Reference fields always hold the Id. – Fernando Gavinho Jul 25 '16 at 13:26
  • Can you explain what you mean by the watched fields? – Griffin Jul 25 '16 at 13:27
  • If your matching rules watches the FirstName, LastName and AccountId fields. The duplicate rules will only fire if you make changes to one of those fields (not sure if this is on the docs, but It happened on my tests) – Fernando Gavinho Jul 25 '16 at 13:28
  • At a code level I know you're right but when it comes to Salesforce Config and picklist values Account Name tends to be the actual account name. Like in merge fields on email templates the field isn't the Id but the actual account. – Griffin Jul 25 '16 at 13:28

Not the answer you're looking for? Browse other questions tagged or ask your own question.