Take a look at XF\Mvc\FormAction to better understand form actions.
Tl;Dr
PHP:
$form->complete(function ($form) use ($store) {
// get the id of the entity that was saved
$entityId = $store->getEntityId();
// get the last insert id (might be smth. completely different or even 0)
$lastInsertId = \XF::db()->lastInsertId();
});