The commitWork() method in the class fflib_SObjectUnitOfWork has a predefined order of execution that always sends the emails at last, as it can be seen as follows:
private void doCommitWork()
{
onCommitWorkStarting();
onPublishBeforeEventsStarting();
publishBeforeEventsStarting();
onPublishBeforeEventsFinished();
onDMLStarting();
insertDmlByType();
updateDmlByType();
deleteDmlByType();
emptyRecycleBinByType();
resolveEmailRelationships();
onDMLFinished();
onDoWorkStarting();
doWork();
onDoWorkFinished();
onCommitWorkFinishing();
}
private void doWork()
{
m_workList.add(m_emailWork);
for (IDoWork work : m_workList)
{
work.doWork();
}
}
I would like to send the emails first and then execute the update DML. Is this possible? I would like to send an email with the state of the objects before updating the objects but with the fflib unit of work I am forced to always send the emails at last.