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
Satyajit SinghSatyajit Singh 

How to prevent deleting event Relation from event?

Hi,

How can i restrict a user from removing attendees from a created event?
Can i do this using trigger? If so then how?
Please respond!

Thanks,
Ankit AroraAnkit Arora
I don't think this is doable, as we can write a trigger on Event but not able to track "EventRelation". We can get the current count of EventRelation but not able to get it from Trigger.new and Trigger.ol as they both returns same value. But this is just to give you an idea, and worht trying. Let me know if it helps.

Code is rough, and just for POC, my be it will help you in a way (also may be am wrong)
 
trigger TriggerOnEvent on Event (before update)
{
    List<EventRelation> newEve = [select Id,RelationId from EventRelation where EventId =: Trigger.new ] ;
    List<EventRelation> oldEve = [select Id,RelationId from EventRelation where EventId =: Trigger.old ] ;
    
    If(oldEve.size() != newEve.size())
    {
        System.debug('Throw Exception Here') ;
    }
    else
    {
        System.debug('No Attendee Deleted') ;
    }
}

Thanks
Ankit