You need to sign in to do that
Don't have an account?

Trigger to track what a previous Case Record Type is?
Hello,
We have situation where people are changing Case Record Type from one to another. I know we can track this by turning on the history tracking. But we want a way to see it as a field on the Case.
So I need to capture the old value of Record type in Old Value field
Record Type. 1) Regular 2) Strategic
Text field: Old Value
Can anyone help me to write an trigger?
Thanks a lot!
Shruti
If you want to store the Old Record Type Id then the above code (posted by sales force) will work. However if you want to store the record type name then try the below one
trigger StoreOldRecordType on Object(before update) {
map<Id, RecordType> mapRecordTypes = new map<Id, RecordType> ([select id, name from recordtype where sobjecttype='OBJECT API NAME']);
for(Object var : trigger.New) {
var.Old_Value__c = mapRecordTypes.get(trigger.oldMap.get(var.id).RecordTypeId).Name;
}
}
Let me know if it helps.
All Answers
trigger triggerName on Object(before update)
{
for(Object var : trigger.New)
{
var.Old_Value__c = trigger.oldMap.get(var.id).RecordTypeId;
}
}
If you want to store the Old Record Type Id then the above code (posted by sales force) will work. However if you want to store the record type name then try the below one
trigger StoreOldRecordType on Object(before update) {
map<Id, RecordType> mapRecordTypes = new map<Id, RecordType> ([select id, name from recordtype where sobjecttype='OBJECT API NAME']);
for(Object var : trigger.New) {
var.Old_Value__c = mapRecordTypes.get(trigger.oldMap.get(var.id).RecordTypeId).Name;
}
}
Let me know if it helps.