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

How can I create Tasks with a specific record type by trigger?
Hi
I am creating tasks by trigger using code: Can anyone suggest ,How can I create Tasks with a specific record type by trigger? using this code?
Task tsk = new Task(whatID = ID, Ownerid =user.id, Subject = 'XYZ', ActivityDate = DueDate.date() , IsReminderSet = true);
tasks.add(tsk);
You can try this :
All Answers
You can try this :
Thanks it solved my problem. :-)
HI,
Use the below code to create task with specific record type.You can get the id of the particular record type withour perform query in recordType object:
final string taskRecordType = 'Name of record type';
Map<String, Schema.RecordTypeInfo> taskRecordTypes = new Map<String, Schema.RecordTypeInfo>();
Id taskRecordTypeId;
taskRecordTypes = Schema.SObjectType.Task.getRecordTypeInfosByName();
taskRecordTypeId = taskRecordTypes.get(taskRecordType).getRecordTypeId();
Task tsk = new Task(
whatID = ID,
Ownerid =user.id,
Subject = 'XYZ',
ActivityDate = DueDate.date() ,
IsReminderSet = true,
RecordTypeId = taskRecordTypeId /* Assign record type Id.*/
);
tasks.add(tsk);
Thanks puja..
Actually I am getting recordTypeID by custom label.