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
Leonardo Girgenti 5Leonardo Girgenti 5 

Trigger please help

Hello all,
I have a custom object called Meetings.
I have a join called Meeting Participants between Meeting and Contacts called Contacts_in_bilaterals__c.

I would like a trigger to fire everytime there is a new Meeting Participants added in the join to go and populate the concatenated name and title of the Contact (I have already that field on the Contact) in a freetext field on the Meetings record.
Would like to have is to if new meeting participants are added, the new ones come under the one already there, pehaps separated by a carriage return or else.
Thanks
Bhanu MaheshBhanu Mahesh
Hi Leonardo,

Assuming api names of meeting as Meeting__c , contact as Contacts_in_bilaterals__c and join as Meeting_Participants__c

The field to be updated on meeting as textAreaFied__c and the field from contact with title and name as NameWithTitleField__c

Not sure about API Names modify the API names where ever required

Try below code
trigger UpdateContactOnMeeting on Meeting_Participants__c(after insert){
	set<Id> meetingIds = new set<Id>();
	set<Id> contactIds = new set<Id>();
	Map<Id,Meeting__c> mapMeetingWithId = new Map<Id,Meeting__c>();
	Map<Id,Contacts_in_bilaterals__c> mapContactWithId = new Map<Id,Contacts_in_bilaterals__c>();
	for(Meeting_Participants__c meetngPart : trigger.new){
		meetingIds.add(meetngPart.Meeting__c);
		contactIds.add(meetngPart.Contacts_in_bilaterals__c);
	}
	if(!meetingIds.isEmpty() && !contactIds.isEmpty()){
		for(Meeting__c meeting : [SELECT Id,textAreaFied__c FROM Meeting__c WHERE Id IN : meetingIds]){
			mapMeetingWithId.put(meeting.Id,meeting);
		}
		for(Contacts_in_bilaterals__c contact : [SELECT Id,NameWithTitleField__c FROM Contacts_in_bilaterals__c WHERE Id IN : contactIds]){
			mapContactWithId.put(contact.Id,contact);
		}
	}
	for(Meeting_Participants__c meetngPart : trigger.new){
		if(meetngPart.Meeting__c != null && meetngPart.Contacts_in_bilaterals__c != null && mapMeetingWithId != null && mapMeetingWithId.get(meetngPart.Meeting__c) != null && mapContactWithId != null && mapContactWithId.get(meetngPart.Contacts_in_bilaterals__c) != null){
			Meeting__c meeting = mapMeetingWithId.get(meetngPart.Meeting__c);
			if(String.isBlank(meeting.textAreaFied__c)){
				meeting.textAreaFied__c = mapContactWithId.get(meetngPart.Contacts_in_bilaterals__c).NameWithTitleField__c;
			}
			else{
				meeting.textAreaFied__c = meeting.textAreaFied__c + ' \n' + mapContactWithId.get(meetngPart.Contacts_in_bilaterals__c).NameWithTitleField__c;
			}
			mapMeetingWithId.put(meeting.Id,meeting);
		}
	
	}
	if(mapMeetingWithId != null && mapMeetingWithId.values().size() > 0){
		update mapMeetingWithId.values();
	}
}

Regards,
Bhanu Mahesh