Developer Docs - Helix - DB Transaction
MOVED TO LAVA DOCS
Discovering the capability to modify data might lead you to scenarios where altering multiple entities simultaneously becomes necessary. Imagine wanting to add a new group and then immediately add a member to that group. This seems straightforward, until you encounter an error while adding the group member—perhaps due to validation issues or incorrect data. This would leave you with a new group but no members.
Modern applications address this challenge with the concept of transactions, which bundle changes together so that if one action fails, all changes are reverted, or 'rolled back'. Helix embraces this modern approach, recognizing the importance of supporting such scenarios. Frankly, we introduced transaction blocks partly out of convenience; it saves us the effort of manually writing Lava logic to undo changes when errors occur, ensuring the system remains efficient and user-friendly.
{% dbtransaction %}
{% modifygroup id:'0' %}
[[ property name:'Name' ]]Ted's Traveling Circus[[ endproperty ]]
[[ property name:'GroupTypeId' ]]26[[ endproperty ]]
{% endmodifygroup %}
{% modifygroupmember id:'0' %}
[[ property name:'PersonId' ]]{{ CurrentPerson.Id }}[[ endproperty ]]
[[ property name:'GroupId' ]]{{ ModifyResult.Group.Id }}[[ endproperty ]]
{% endmodifygroupmember %}
{% enddbtransaction %}
{% if TransactionResult.Success == false %}
{{ TransactionResult.ErrorMessage }}
Validation Messages
{% for message in TransactionResult.ValidationErrors %}
- {{ message.ErrorMessage }}
{% endfor %}
{% endif %}
Database transactions are currently supported exclusively for encapsulating Modify Entity commands.