2

I am re-creating a sort of Teams functionality for a custom object by creating an object called Team (master-detail to the parent object) and then a look-up relationship from this to users (Team Members).

When the parent/master record gets updated I want to send an email to all of the users who are part of the team but I can't figure out how to get the email to trigger. If I link the email to the master object I can't select the users in the detail records. If I link the email to the detail object then I can't figure out how to get changes to the master object to trigger the detail object to change and therefore trigger the workflow rule.

Any ideas?

1 Answer 1

0

How about just collecting e-mail adresses from child records?

Map<Id, Team__c> teamMap = Map<Id, Team__c>(SELECT Id, (SELECT Id, Name, User__r.Email 
                                                        FROM Team_Members__r )
                                            FROM Team__c
                                            WHERE Id iN : trigger.new);

Map<Id, String[]> Adresses = new Map<Id, String[]>();
for(Team__c team : teamMap.values()){
    Adresses.put(team.Id, new String[]{});
    for(Team_Members__c tm :team.Team_Members__r){
       if(tm.User__r.email != null){
           Adresses.get(team.Id).add(tm.User__r.email)
        }          
    }    
}

When you have this map it will be easy to send mails :)

You can also create workflows rules on child objects and just update them from parent trigger (eg. create checkbox and use it as entry criteria, then after send mail workflow should set it to preverious value )

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .