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
Yelper DevYelper Dev 

Primary Contact - Contact Trigger Handler

Hello, Can anyone help me with the following requirements? The even of the trigger is before Insert.

[1] If there is no contact records on the Account, the new contact record should be automatically be the primary contact (Checkbox field)

[2] If 2 Account has no contact records, the 2 new contact records should be automatically be the primary contact.

[3] If the Account has already a contact record that is already a Primary, it should prompt an error message "Already has primary contact"

Contact Trigger:
trigger ContactTrigger on Contact (before insert, before update) {
         ContactTriggerHandler.onBeforeUpdate(, Trigger.oldMap);
Thank you.