last day (14 days later) » 

13:25
2
A: Duplicate rules not triggering

Fernando GavinhoWhat 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 ...

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
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.
Can you explain what you mean by the watched fields?
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)
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.
13:25
If you use an <apex:outputField> with a reference field (wich holds the Id) salesforce will also display the Name. A quick way to test it, is to create your rule using the Account Name and then create two accounts with the same name and see if the duplicate rules block contacts with the same name on different accounts. I'm can't test it right now, but I'll run some tests later to confirm that.
Yeah I'm about to run that test.
I have bad bad news. I just tested it and Account Name is the actual name of the account not the Id. :( I was hoping man. I was hoping big time.
Yeah. you're stuck with the trigger than. This question presents the exact same problem.
@Frenando Not going to be your favorite person here but I just tried it and while the field is populating off the trigger correctly it doesn't fix it.
Can you share you trigger logic?
Added my trigger logic to the question
@FernandoGavinho you there?
14:04
Yes yes. Let me take a look
Just to be sure: Did you test it with a contact that is not on the invalid contact recordtype?
hehehe
Yes, the triggers work right when the record type is Active. But when the record type is inactive there are problems
You're saying that for active contacts, the duplicate rule works?
.... It was working... Now it's not.
And for inactive it doesn't? Is the recordtypeId on the custom setting correct?
Now it's just not working at all
14:10
Oh man. =/
I tested on my dev org. For active contacts it should be working fine. Do this: remove the check for recordtype and just check if the accountID is empty.

if(c.AccountId != null) c.Account_Id__c = c.AccountId;
and test again with new contacts.
That's a much cleaner check.
just for now
you can also check like this:


if(c.AccountMap__c != null) c.Account_Id__c = c.AccountMap__c ;
else if(c.AccountId != null) c.Account_Id__c = c.AccountId;
Not working again
Well still not working
Let me fix it back to where it was and I'll get back to you
Did you create new contacts on the same account or used old ones?
New contacts.
Dealing with old ones is too complicated for now
14:19
man. that's strange.
I'm going to try the classic turning it on and off again (the duplicate rule)
how is you trigger looking like right now?
Usually at this point in time, I usually take a step back and see if I'm testing correctly.
if(Trigger.isBefore && !Trigger.isDelete){
    for(Contact c : trigger.new){
       // if(c.AccountId == null){
       //     c.Account_Id__c= c.AccountMap__c;
       // }
        //else{
            c.Account_Id__c = c.AccountId;
        //}
    }
}
Turned off everything but the basics
Going to slowly start adding things back to see if it breaks
if(Trigger.isBefore && !Trigger.isDelete){
for(Contact c : trigger.new){
if(c.AccountId == null){
c.Account_Id__c= c.AccountMap__c;
}
else{
c.Account_Id__c = c.AccountId;
}
}
}

Still working
Even works to block the creation of inactive contacts when there are dupes
This way it'll not work correctly if both AccountId and AccountMap__c are empty. But you should be good to go
@FernandoGavinho Okay, if QA decides this is acceptable I'll give you the bounty. Normally I wouldn't since at a core you essentially linked me to another answer but if you set this crap up in your box that's a significant amount of effort.
Scratch that just gave it to you now. Thanks for your help.
14:34
You're welcome.
o/
On my end it works and at this point anyone who disagrees with that statement can blow me
Glad I could help. It was a nice thing to learn eheheh
Wouldn't call it nice. More like painful when it carries over to the next sprint
Just leave a pretty comment on the trigger and forget about it. heheheh
Oh they're not going to be happy I shoved that in the actual trigger and not the ContactUtils
But yeah

last day (14 days later) »