You need to sign in to do that
Don't have an account?
Brandon Gittelman 2
Account Contact Relationship -- Only have 1 Primary contact able to be checked
Since our recent move to Lightning, we've lost the ability to use the Contact Roles feature on our Accounts.
The given response from salesforce is to use the Account Contact Relationship object and add a checkbox called "Primary" (Primary__c)
This has been working well, but this unfortunetely doesn't prevent our sales reps from accidently selecting multiple primary contacts.
I believe what I'm needing is a trigger on the AccountContactRelationship object that will prevent multiple people from being checked and display an error.
I've found a few trigger codes that say they work, but all seem to error out when complied in my sandbox org as I don't believe they were written for the AccountContactRelationship object
The given response from salesforce is to use the Account Contact Relationship object and add a checkbox called "Primary" (Primary__c)
This has been working well, but this unfortunetely doesn't prevent our sales reps from accidently selecting multiple primary contacts.
I believe what I'm needing is a trigger on the AccountContactRelationship object that will prevent multiple people from being checked and display an error.
I've found a few trigger codes that say they work, but all seem to error out when complied in my sandbox org as I don't believe they were written for the AccountContactRelationship object
Can you make sure Contacts to Multiple Accounts Settings is enable in your sandbox?
Also please share the trigger code for review?
Here is a trigger code which might help you resolve the puzzle. I have created a custom object named AccountContactRelationship_Custom__c in order to compherend the requirement.
Here we go,
Note: You will have to put your object name in place of AccountContactRelationship_Custom__c (which is probably AccountContactRelation)
You will have to put your field name in place of AccountId__c & ContactId__c (which is probably AccountId & ContactId accordingly)
You will also have to flip Primary_Contact__c to your own field (which is Primary__c I believe) Above trigger will prevent second primary contact for a account on insert and update operation.
Brandon, if this helps to solve your question then please mark it as the Best Answer!
Regards,
Harshil Parikh
That worked in Sandbox!
However when I'm trying to push it to Prod, it's failing with 0% code coverage.
Here is a test class I can offer for you to deploy the trigger. However, I would suggest you to go through the class and modify as necessary.
Here we go,
I have tested an above test class and its giving 100 code coverage to below trigger I have mentioned in above post:
Hope this helps. If it resolves your query, please mark it Best Answer!
Thank you.
Harshil Parikh