How to use Calculated Attribute?

I am working in an app called Hospital management systems, their is one scenario where I want to display number of available beds and when I assigned one bed to a patient then total number of beds should be reduce by one. How can I achieve this using Calculated attribute and what will be logic in the microflow. Please help. Thank you!
2 answers

Be sure to check if you actually want to use a calculated attribute or not. There's some documentation about that here:


Performance Best Practices


You can either do this with a calculated attribute, or by updating an attribute each time you assign a bed.

I'm going to make some assumptions about your domain model since you did not include it in your question.


If you were to make the AvailableBeds a calculated attribute, you could make a flow that looks something like this:


Edit: changed the order of my answer to highlight the importance of deciding whether or not you want to use a calculated attribute




I wouldn’t use a calculated attribute as each time you retrieve this entity it will recalculate. The next easiest thing would be to use a after commit Event Handler that calculates the required values.