Groovy 41 – Create a Field that will keep track of how many updates happen on an Opportunity Revenue Line
Opportunity Revenue Revision
Create a text field called Revision_c on the Opportunity Revenue Object. Set the default fixed value to Update 0.
Now create a trigger on Opportunity Revenue of the type "Before Update" with the following code:
if (PrimaryFlag == 'N' && getPrimaryRowState().isModified() && Revision_c != null) { String initialString = Revision_c.toString(); if (initialString != "") { def number = Integer.parseInt(initialString.replaceAll("[^0-9]", "")); number++; def updateString = "Update " + number; setAttribute('Revision_c', updateString); } }
Now each time a new revenue line is added, the field Revision_c will have the value "Update 0". After making changes to the revenue line and clicking save, the value of Revision_c should increment, becoming "Update 1", "Update 2", and so on, after each change.