Posts

Showing posts from August, 2020

Run as different user in Apex

Yes, you read it right; running apex as different user who has higher access levels than logged in user is now possible in Salesforce using Platform Events . Platform events are executed as  Automated Process user . Processing records in system mode or async apex like  batch jobs are the commonly used workarounds for this. However there are few use cases where these workarounds can not help. We are going to see one of such use case. Use Case: If event is created with attendees then, only organizer can edit the event. This is standard Salesforce behavior. And there is business requirement that, attendees should be able to update few fields on event. Solution: Lets first analyze what is event with attendees means. Whenever a event is created with attendees, Salesforce creates separate events for organizer and attendees. These events are linked to each other, any update to organizer event is propogated to all attendee events automatically.  For organizer event IsChild is set to false an