I have the below requirement to be implemented in a plugin code on an Entity say 'Entity A'-
Below is the data in 'Entity A'
Record 1 with field values
- Price = 100
- Quantity = 4
Record 2 with field values
- Price = 200
- Quantity = 2
I need to add the values of the fields and update it in a new record. Example shown below -
Record 3
- Price = 100 + 200 = 300
- Quantity = 4 + 2 = 6
Entity A has a button named "Perform Addition" and once clicked this will trigger the plugin code.
I need some ideas/pseudocode on how can i implement this. The example explained above is just a simpler version of my entity. In Real the entity has more than 60 fields on it , and for each of the fields i need to perform the sum and update in the third one. Also the number of records on which the addition would be performed can be beyond 2.
Hence more the no of records, more i will have to loop through each records and perform sum, I would like to know if there are simpler and better ways to writing this logic.
Just need guidance on how the logic should be written. Any help would be appreciated.