You need to sign in to do that
Don't have an account?

Retrieve email addresses from primary contacts of account
Hello everyone,
All our accounts have one or several "primary" (simply checkbox) contacts related to to them.
I want to retrieve all those emails and gather them in a long text area field on the account. I found some sample code which retrieves the email but only for the first contact it finds.
Little bit of background:
Whenever someone opens a ticket related to this account we want the email addresses of all primary contacts automatically populated into the "additional to" section. I got this part sorted but can`t seems to get the email addresses into the account.
Do you have some guidance on how to retrieve all emails ?
Code I found:
trigger RetrieveEmails on Account (before update) {
for (Account acc : Trigger.new) {
Contact[]contactR = [select ID, Email from Contact where Primary_Contact__c = true and AccountId= :acc.id ORDER BY Primary_Contact__c DESC, createdDate limit 1];
if (contactR.size() > 0) {
acc.Description = contactR[0].Email;
}else{
acc.description = 'DEBUG; CONTACT = null ';
}
}}
Thanks very much in advance!
Christian
Try this.
All Answers
Try this.
Hi Dhaval,
Awesome!!! It works like a charm! Thank you so much!!!
Have a great day and thanks again,
Christian