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
SFDC n12SFDC n12 

Trigger Help needed


I need help on the following req

1) I am having a custom field called as "Dealer Principal__c" in my custom object called as "Account Exceptions__c"

2) There is a lookup on my custom object called as Account__c which is a lookup to the account object

My req is i want to populate my custom field  "Dealer Principal__c"  on Account exception__c custom object with  the contact first name and last name of the contact  related to the account that i select if the contact title is set as "Dealer Principal" (This is done)

if the account record type is group account , the child accounts contact's name  is set which is having 
contact title as "Dealer Principal"  and not the group account contact  (need help on it)

My requirement is below 

1) if the account is a normal account (PDN Record type) , the contact(name) associated with that account with title "Dealer Principal" is populated to that field

2) If the account is a group account

the group account might have many child accounts , where it will check the contacts of all th e child accounts with the title "Dealer principal" and update the name correspondingly

so my case should work for both the scenarios

First scenario my trigger is working fine , just need help on second one

My trigger :

trigger updateaccountexceptions on AccountExceptions__c(after insert) {
    map < id, string > dealercontacts = new map < id, string > ();
    set < id > accids = new set < id > ();

    for (AccountExceptions__c acex: {

    List < contact > cons = new List < contact > ([select Id, accountid, firstname, lastname from contact where title = 'Dealer Principal'
        and accountid = : accids

    for (Contact con: cons) {
        string conname = con.firstname + ' ' + con.lastname;
        dealercontacts.put(con.accountid, conname);

    list < AccountExceptions__c > acexlisttoupdate = new list < AccountExceptions__c > ();

    for (AccountExceptions__c acex: {
        AccountExceptions__c accex1 = new AccountExceptions__c();
        if (dealercontacts.containskey(acex.account__c)) {
            accex1.Dealer_Principal_s__c = dealercontacts.get(acex.account__c);

    update acexlisttoupdate;


Help me how to get the child account contacts name for account record type is group account

Thanks in Advance
PratikPratik (Salesforce Developers) 

Is this issue resolved as i come across the similar post from you. Please let us know through post.

SFDC n12SFDC n12
yes got it resolved