I have a 2 level approval process. At the end of 2nd final level approval - the status field on the object is set to APPROVED. I have a trigger on after update, after insert, etc... on custom object that creates an Event in user calendar when status=approved.

Expected behaviour: The event should be created by the user who is the owner of my custom record.

What is happening: The event get created but the created by = last approver instead of record owner. It assigns the event to current user properly. I have already tried system.runAs(user) but its not work for me. Is there any other workaround?

  • Would you able to post your code Feb 13, 2017 at 19:59

1 Answer 1


This is I believe expected behavior.

The trigger executes when the approver approves the record, so the actor/current user in this scenario is the final approver, so any record created in this transaction will have the final approver as record owner unless specified.

So you will have to fetch the custom object record's owner Id in the trigger and assign to the OwnerId of the event record you are creating.

  • i know that and i already assign the records owner id but i want to assign created by id
    – Faisal
    Feb 14, 2017 at 16:23
  • I am afraid thats not possible. CreatedById is not writable. However you can manually set this field value while inserting records using Data loader with special permission, see this link for more info on that. But its definitely not possible using apex. Feb 14, 2017 at 17:43

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .