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
montezmontez 

Roll up Unique Contact field value to Parent Account field - Trigger Needed

I need a trigger that pulls all the unique values from Email Domain (custom field) and populates the field Domain Mapping (managed package custom field) separated by a single space and only unique values.

Example:
Account XYZ has three contacts.
Contact 1 has a Email Domain of XYZ.com
Contact 2 has an Email Domain of ABC.com
Contact 3 has an Email Domain of XYZ.com
Accounts Domain Mapping field should be “XYZ.com ABC.com”

Object - Field - API Name
Account - Domain Mapping - Zendesk__Domain_Mapping__c
Contact - Email Domain - Email_Domain__c

Can you help?
pconpcon
It sounds like you're looking for someone to write the code for this project. These forums are not meant for that; you'll want to post over on the AppExchange site [1] where you can match up with a developer looking to work on your project.  If you have a trigger that you have attempted to write that is not working as expected, please include it here we can help you troubleshoot your issues.

NOTE: When including code please use the "Add a code sample" button (icon <>) to increase readability and make referencing code easier.

[1] https://appexchange.salesforce.com/developers
montezmontez
Thanks PCON. Reading it now it looks like I am asking for some free dev. My mistake. I was looking for some ideas on how to get started. Do you know if the ask is possible and/or of certain functions I could use. I am looking to get started on the trigger.

I will post my code once I get past the early stage.
pconpcon
What I would do is in an after insert / update trigger I would get a set of AccountIds for any Contacts whose Email_Domain__c has changed (or is set if it's an insert).  Then I would query all contacts under those accounts.  I would build a map of account Ids to a list of contacts.  Then iterate over each of those contacts and then make a set of domains.  Then join those domains using String.join [1].  Take a look at the psuedo code below
 
for (Contact in Trigger.new) {
    if (Trigger.isInsert or Email_Domain__c has changed) {
        accountIds.add(contact.AccountId)
}

for (Contact in Accounts where Id in accountIds) {
    accountMap.get(contact.Id).add(contact)
}

for (Id in accountMap.keySet()) {
    for (Contact in accountMap.get(id)) {
        domainSet.add(contact.Email_Domain__c)
    }

    accountsToUpdate.add(new Account(
        Id = id,
        Zendesk__Domain_Mapping__c = String.join(domainSet, ' ')
    )
}

if (has accountsToUpdate) {
    update accountsToUpdate
}

[1] https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_methods_system_string.htm#apex_System_String_join