+ Start a Discussion
Satyananda YeluriSatyananda Yeluri 

Record Versioning


  I have been struggling with achieve record version. My requirement is: system should create a new record by incrementing version number whenever a change made on record. Can anybody help me to achieve this functionlaity. Would be appreciated your help. 


Hi Satyananda,
1) Create a field as number field to capture version
2) Create a workflow to fire every time a record is created or edited
3) In workflow criteria check if any of the field on your record is changed if you only want to version of there was a change on the record
4)Use ISCHANGED(FIELD_NAME) method on your criteria
5) Use field update action to update your version field.

Fahad Akhtar

Satyananda YeluriSatyananda Yeluri
Hi Fahad, 

   Thank you. I have 200 fields on object and 30 layouts and record types. And, I need a new record whenver a change made on existing record.

Abhishek BansalAbhishek Bansal
It can be easily done with the help of trigger.
Use below Code :
trigger createNewRecord on YourObject(after update){
	List<YourObject> insertList = new List<YourObject>();
	YourObject objRecord;
	for(YourObject obj : trigger.new){
		objRecord = new YourObject();
		//Add all the fields which you want to populate in new record
	insert insertList;
//Replace YourObject with API name of your Object
Let me know if you need more help on this.

Satyananda YeluriSatyananda Yeluri
Hi Abhishek, 

Thank you.
    But, the existing record will be upadated with new values???

    I have record X - version 0.1
    I have updated version 0.1 with new value 
    Now, I need to see version 0.2 with new value and version 0.1 should not be effected. (above snippet, version 0.1 updated with new values ?? )

Can you please let me know if my understanding is wrong. 

I appreciate your help. 


Abhishek BansalAbhishek Bansal
Hi Satya,

What you are trying to achieve is not possible because we are creating a new record when an existing record is updated and your requirement suggests that you do not want to change the existing record.
So if the existing record is not allowed to update than how would we get to know that a record has been updated.

The only solution is we can create new records with the old values with the help of trigger.old which means that your existing record will update and a new record will e created with old values.

Eg : Record A - Version 0.1 => Updated To Record A - Version 0.2 than we can create a new record with vaue = Record B - Version 0.1

Please let me know if this information is helpful to you or not ?

Satyananda YeluriSatyananda Yeluri
Hi Abishek, 

  as per your example, we are cloning Record A as Record B (Auto Id and Created Date/Time will get change) and Record A updated as 0.2 which is an issue. 

My requirement is basic versioning of records.

 I have created Record A with status 'Unprocessed' and version 0.0
 Updated Record A with status 'In Progress' 
  The above action should create a new record (say Record B and version 0.1, status = 'In Progress')
  The Record A should retain the old values (Status = 'Unprocessed' and version 0.0)

I am looking for any other alternative solution if the trigger does not work. I tried using clone. but, that actually saves if i don't do update and save.
Abhishek BansalAbhishek Bansal
Impossible with trigger unless you take help of another Custom Object which will store Old andNew Values of your object and than insert the new values and again update the curent with old one's.
Satyananda YeluriSatyananda Yeluri
Thanks Abhishek. 
Data Integration 46Data Integration 46
it could be done using triggers by adding another field to your table invisible_status, a technical field, not visible for users.
The trigger will create a new record when this field is updated.
hi satyananda yeluri ,
i   need solution for your question .if you have solution pls upload