I have been following this exercise here.
https://trailhead.salesforce.com/projects/salesforce_developer_workshop/steps/creating_triggers
Session__c
and Speaker__c
are parent objects.
Session_Speaker__c
is a junction object relating the above.
This is the email sending trigger that sends an email to the speaker as soon as they are assigned to a session.
trigger SendConfirmationEmail on Session_Speaker__c (after insert) {
//collect ID's in one list of a single SOQL query
List<Id> sessionSpeakerIds = new List<Id>();
for(Session_Speaker__c newItem : trigger.new) {
sessionSpeakerIds.add(newItem.Id);
}
// Retrieve session name and time + speaker name and email address related to ID's
List<Session_Speaker__c> sessionSpeakers =
[SELECT Session__r.Name,
Session__r.Session_Date__c,
Speaker__r.First_Name__c,
Speaker__r.Last_Name__c,
Speaker__r.Email__c
FROM Session_Speaker__c WHERE Id IN :sessionSpeakerIds];
if(sessionSpeakers.size() > 0) {
// Send confirmation email if we know the speaker's email address
Session_Speaker__c sessionSpeaker = sessionSpeakers[0];
if (sessionSpeaker.Speaker__r.Email__c != null) {
String address = sessionSpeaker.Speaker__r.Email__c;
String subject = 'Speaker Confirmation';
String message = 'Dear ' + sessionSpeaker.Speaker__r.First_Name__c +
',\nYour session "' + sessionSpeaker.Session__r.Name + '" on ' +
sessionSpeaker.Session__r.Session_Date__c + ' is confirmed.\n\n' +
'Thanks for speaking at the conference!';
EmailManager.sendMail(address, subject, message);
}
}
}
I believe this trigger is not bulkified.
What if I load records into this junction object via dataloader, then this trigger will fire only for the first record in the incoming trigger collection.
Am I right ?