+ Start a Discussion
amruta_dhumalamruta_dhumal 

How to set fieldvalue to it's priorvalue on recordtype change

Hi

 

I've Account & opty object.opty shared 22 recordtypes.when opty recordtype status is 'xxx' then it's updating Account field value to 'xxx' through trigger.

 

Now when I change recordtype to another [thru Change Link option beside recordtype] then it should set 'None' value on previous recordtype related Acct field.

 

Any suggestions how this can be achievable?

 

Amruta

Jeff MayJeff May

Why would the previous record type be "None" when you switch from one record type to another one?  Wouldn't it be the old record type?  If you just want to clear the value in the related Account field, use null in your trigger.

 

Accountfield__c = null;

 

amruta_dhumalamruta_dhumal

Actually my req. is old recordtype value should be update with new recordtype status value.

 

If new RT value is 'xxx' then it will update Account field 'status1' as 'xxxx',at that moment old RT value for that Acct field 'status2'  is also set as 'xxx'.

 

Amruta 

Jeff MayJeff May

got it.  In an update trigger, you can use the trigger.oldMap() to get the prior value.

 

trigger.oldmap.get(odbj.Id).fieldname

 

 

amruta_dhumalamruta_dhumal

but how I can identify through trigger that recordtype is changed??

 

Amruta

Jeff MayJeff May

you can compare the current value to the one in oldmap.

 

if "l" is the object in your trigger, then

 

if (l.RecordType != trigger.oldmap.get(l.Id).RecordType) {

 

}