You need to sign in to do that
Don't have an account?
dlCamelot
Trigger Help - Cross-Object Update
Hi all,
I'm so close to getting this trigger to work, but could use some help with the last bit. For context, this is a cross-object (child to parent) relationship - Event Attendence (child) adds/edits will update a date field on the Contact (parent). What do I need to adjust?
trigger Contact_Update on EventAttendance__c (before insert, before update) {
//Holds Ids of Event Attendence Records
Set<ID> eventattendIDs = new Set<ID>();
//Maps Contact IDs to Event Attendence Date
Map<ID,DATE> c2ea = new Map<ID,DATE>();
for(EventAttendance__c ea: Trigger.new){
eventattendIDs.add(ea.id);
system.debug('This the event attendence record being added:'+ ea.id);
}
List<EventAttendance__c> lastDate = [SELECT Event_Date__c FROM EventAttendance__c WHERE Contact__c = :eventattendIDs ORDER BY Event_Date__c DESC LIMIT 1];
system.debug('This is the date pulled by SoQL' + lastDate);
for (Contact c: lastDate) {
lastDate.Last_Event_Date__c =
trigger.newMap.get(c2ea.date);
}
update eventattendIDs;
}
Newbie here so please explain the logic for your changes.
I'm so close to getting this trigger to work, but could use some help with the last bit. For context, this is a cross-object (child to parent) relationship - Event Attendence (child) adds/edits will update a date field on the Contact (parent). What do I need to adjust?
trigger Contact_Update on EventAttendance__c (before insert, before update) {
//Holds Ids of Event Attendence Records
Set<ID> eventattendIDs = new Set<ID>();
//Maps Contact IDs to Event Attendence Date
Map<ID,DATE> c2ea = new Map<ID,DATE>();
for(EventAttendance__c ea: Trigger.new){
eventattendIDs.add(ea.id);
system.debug('This the event attendence record being added:'+ ea.id);
}
List<EventAttendance__c> lastDate = [SELECT Event_Date__c FROM EventAttendance__c WHERE Contact__c = :eventattendIDs ORDER BY Event_Date__c DESC LIMIT 1];
system.debug('This is the date pulled by SoQL' + lastDate);
for (Contact c: lastDate) {
lastDate.Last_Event_Date__c =
trigger.newMap.get(c2ea.date);
}
update eventattendIDs;
}
Newbie here so please explain the logic for your changes.
James Loghry
Think we might need a bit more context on the use case, but here's what I think you're going for. See my comments for an idea of how the trigger (should) work. Keep in mind, this is late on a Friday and I'm at least one scotch into the night, so it might not compile on the first shot :-D
James Loghry