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
kritinkritin 

change the Record type of Opportunity on delete.

I needed one help with respect to writing of one trigger on Opportunity for before delete trigger. my objective is to We want to change the record type of opportunity to Deleted Opportunity once user cliks Delete button. I know we can override button with S-Control/javascript. but i want to build this login Opportunity trigger. means change the Record type of Opportunity on delete and prevent this from deletion of record without adding any error.

Pradeep_NavatarPradeep_Navatar

In trigger code before delete you change the Record Type. Below is a sample code that to change record type :

 

                RecordType RecType = [Select Id from RecordType where and SobjectType ='Opportunity' limit 1];

                Opportunity opp = [Select id, RecordTypeID From Opportunity limit 1];

                opp.RecordTypeID = RecType.id;

                update opp;