function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
chinuchinu 

Help me with trigger...

Hi,
Please help me out with trigger…

In the contact object if we are giving the details of contact (for e.g., email) if we are giving the same email id which was given for first time then it should accept(i.e., accepting the dupliactes).
When the same thing (mentioned above) is doing in the Account object related list of contact then it should not allow the duplicates.
Abdel-Ali BOULIKAAbdel-Ali BOULIKA
Hello,
What I understand is that you want to avoid 2 contacts with same email ID related to a same account.

I think you can implement this requirement whithout a trigger.
Here is an example of how to do that :
1. Create a custom text field on the Contact object, you can give him a name like "Account Contact Email ID unicity". And define it with a unique constraint (case sensitive).
This field will be only a technical field (no need to display it on page layouts).
2. Create Workflow that will be triggered when a Contact is created and whenever it's modified.
As criteria you can set somethink like "Contact Last Name not equal to ''.
3. Create a field update triggered by this workflow, and the field update will assign a value to the custom field (cf. step 1.) using a formula like this one :
IF( ISBLANK(AccountId), null, AccountId & ' ' & Email)
4. Activate the workflow.

The field created in step 1. + the workflow field update defined in step 3. will ensure that :
1. If a contact is not related to an account => the unicity constraint will not trigger any error (because we will assign null value).
2. If we define 2 contacts with same email IDs and assigned to the same account (i.e. same AccountId), the unicity key that we built in step 3. will trigger a unicity error.

So with this solution we can prevent duplicate email IDs for contacts assigned to a same account.
chinuchinu
Hi,
1. I want like when creating the contacts directly from contact object then for eg., giving the same email it has to accept the duplicates.
2. Whereas creating the contacts from the account object contact related list then it should not allow the duplicates email values.
So both the conditions need to work.

Thanks!!
chinuchinu
Hi,
Yes you are right!! I want to avoid two contacts with same email in the related list of account object (not allowing duplicates here). Along with this when creating directly from contact object if the email is same for both contacts it has to accept (here allowing duplicates).so both conditions has to work.

Thanks in advance!!