Groovy 41 – Create a Field that will keep track of how many updates happen on an Opportunity Revenue Line

– Create a text field, I will call mine Revision_c , on Opportunity Revenue Object.

While creating this field add as default fixed value : 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 with have the value Update 0.

After you make some changes to the revenue line and click save the value of field Revision_c, should change to Update 1 and so one, after each change the number should increment.

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *