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
Gabriel Meneses 10Gabriel Meneses 10 

Apex Class Build

I would like help in creating an Apex class that this trigger would call on to achieve the record type change on a Task. It would change the record type based on the Task Subject. I want the Apex class to cause the update, not the trigger.


01trigger TaskRecordType on Task  (after delete, after insert, after update, before delete, before insert, before update) {
02 
03    if(Trigger.isBefore && Trigger.isInsert) {
04     
05        Map<String, Schema.RecordTypeInfo > taskRecordTypes =Task.sObjectType.getDescribe().getRecordTypeInfosByName();
06        Id recordTypeId = taskRecordTypes.get('<b>My Task Name (NOT API)</b>').getRecordTypeId();
07         
08        for ( Task tsk : Trigger.new) {
09            <b>if(tsk.Subject.equals('Condition'))</b>
10                tsk.RecordTypeId = recordTypeId;
11        }
12    }
13}
Raj VakatiRaj Vakati
try this code .. Design this code to fire only on specific events .. 

Like Trigger.isBefore then only fire some logic like thta
trigger TaskRecordType on Task  ( before insert, before update) {
    if(Trigger.isBefore && Trigger.isInsert) {
        Map<String, Schema.RecordTypeInfo > taskRecordTypes =Task.sObjectType.getDescribe().getRecordTypeInfosByName();
         
        for ( Task tsk : Trigger.new) {
		
		 Id recordTypeId = 	taskRecordTypes.get(tsk.Subject).getRecordTypeId();
	    tsk.RecordTypeId = recordTypeId;

        }
    }
}