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
Victoria RileyVictoria Riley 

Event Registration

I have a custom object for event registration.  What is the best way to add up to 10 attendees per registration?
Amit GhadageAmit Ghadage
HI Victoria Riley,
Create Master detail relationship between Attendees and Event Registration,

Write before insert trigger on Attendees
 
trigger attendeesChecker on Attendees__c(before insert)[
Set<Id> attendeesEventKeySet = new Set<Id>();
for(Attendees__c a : Trigger.New)
attendeesEventKeySet .add(a.EventRegistration__c);

Map<Id, Integer> EventRegistrationIdtoattendeeCount = new Map<Id, Integer>();

for(EventRegistration__c er : [select id, (select id from Attendees__r) from
EventRegistration__c  where Id IN : attendeesEventKeySet  ])
{
EventRegistrationIdtoattendeeCount .put(er.Id, er.Attendees__r.size());
}

for(Attendees__c a : Trigger.New)
{
if(EventRegistrationIdtoattendeeCount .get(a.EventRegistration__c) >10)
a.addError('Event is full 10 members are already there);
}
}

I have written code by assuming Object names and Master detail Relationship you make changes of names and fields.


Best Regards,
Amit Ghadage.