[SalesForce] Can you perform DML operations from visualforce email templates

Visualforce email templates allow you to include visualforce components with allowDML="true" but there doesn't appear to be any way to actually use DML. From the docs:

You can't use data manipulation language (DML) operations in a “getxxx” method in a controller.

You can't use data manipulation language (DML) operations in a constructor method in a controller.

You can't use the @future annotation in a “getxxx” or “setxxx” method in a controller, or in the constructor for a controller.

That seems to cover all the ways (I assume batch apex is also not allowed). So is there any way to do this?

Best Answer

I don't think you can use DML in this way. I was able to get some code with DML in it to fire by adding an attribute to the component and executing DML in the setter. However, this results in the following error:

Error occurred trying to load the template for preview: common.apex.runtime.impl.ExecutionException: Attempt to de-reference a null object. Please try editing your markup to correct the problem.

so it looks like there's something about the context that doesn't allow the DML to execute correctly.