> For the complete documentation index, see [llms.txt](https://coldbox-orm.ortusbooks.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://coldbox-orm.ortusbooks.com/advanced/coldbox-orm-event-handler/event-handler-cfc.md).

# Custom Event Handler

![](https://raw.githubusercontent.com/wiki/coldbox-modules/cbox-cborm/ORMEventHandler.jpg)

The ColdFusion documentation says that in order to create a global event handler that it must implement the *CFIDE.orm.IEventHandler* interface. So all you need to do is create the CFC and make it extend the core class that will provide you with all these capabilities: *cborm.models.EventHandler*

```javascript
component extends="cborm.models.EventHandler"{
}
```

That's it! Just by doing this the CF ORM will call your CFC's event methods in this CFC and satisfy the interface. Of course you can override the methods, but always remember to fire off the parent class methods in order for the ColdBox interceptions to still work. You can then override each event method as needed. Below is a chart of methods you can override:

| Listener Method                    | Description                                                                                                                                                    |
| ---------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `postNew(entity)`                  | This method is called by the ColdBox Base ORM Service Layers after a new entity has been created via its new() method.                                         |
| `preLoad(entity)`                  | This method is called before the load operation or before the data is loaded from the database.                                                                |
| `postLoad(entity)`                 | This method is called after the load operation is complete.                                                                                                    |
| `preInsert(entity)`                | This method is called just before the object is inserted.                                                                                                      |
| `postInsert(entity)`               | This method is called after the insert operation is complete.                                                                                                  |
| `preUpdate(struct oldData,entity)` | This method is called just before the object is updated. A struct of old data is passed to this method to know the original state of the entity being updated. |
| `postUpdate(entity)`               | This method is called after the update operation is complete.                                                                                                  |
| `preDelete(entity)`                | This method is called before the object is deleted.                                                                                                            |
| `postDelete(entity)`               | This method is called after the delete operation is complete.                                                                                                  |
| `preSave(entity)`                  | This method is called before the save operation.                                                                                                               |
| `postSave(entity)`                 | This method is called after the save operation is complete.                                                                                                    |
| `preFlush(entity)`                 | This method is called before the Hibernate session is flushed.                                                                                                 |
| `postFlush(entity)`                | This method is called after the Hibernate session is flushed.                                                                                                  |

The base event handler CFC you inherit from has all the ColdBox interaction capabilities you will ever need. You can find out all its methods by referring to the API and looking at that class or by inspecting the ColdBox Proxy class, which is used for enabling ColdBox interactions: *coldbox.system.remote.ColdboxProxy*


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://coldbox-orm.ortusbooks.com/advanced/coldbox-orm-event-handler/event-handler-cfc.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
