function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Satyananda YeluriSatyananda Yeluri 

Record Versioning

Greetings, 

  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. 

Thanks,
Satya
Fahad-AkhtarFahad-Akhtar

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.

Thanks,
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.

Thanks,
Satya
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
		insertList.add(objRecord);
	}
	insert insertList;
} 
//Replace YourObject with API name of your Object
Let me know if you need more help on this.

Regards,
Abhishek.
 
Satyananda YeluriSatyananda Yeluri
Hi Abhishek, 

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

Ex:
    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. 

Thanks,
Satya 

 
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 ?

Regards,
Abhishek.
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.
TIRUMALA SAI TINDIVANAMTIRUMALA SAI TINDIVANAM
hi satyananda yeluri ,
i   need solution for your question .if you have solution pls upload
 
Milan PrasadMilan Prasad
Hello Satyananda Yeluri,

How did yo do the record version at the end ,

I am having same kind of requirement pls help me 
 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)
 
Vijay PendemVijay Pendem
One work around would be :
1. Lock your original record for edit
2. Add clone button on it
3. Once the clone button is hit, the record is cloned and provided in edit mode, let the users update the record before saving.
4. Coming to the versioning part, here is how you can identify if a record is cloned
https://help.salesforce.com/s/articleView?id=000382967&type=1
5. In the same workflow you can add new field for version as well, and keep incrementing it.

Thanks