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
Alex_MAlex_M 

I need to (somehow) get a Task Default RecordTypeId for a particular User (whose User.Id is known).

Hi Everyone!..

 

I’m pretty new to SalesForce, soI hope you can help…

 

I have a trigger which is fired off by an insert into an object (this data is inserted through an API call by an external web app).

 

The inserted data is XML, which after parsing returns a SalesForce UserId of a particular user (among other peaces of data). Depending on the received data numerous actions occur, but the last step is inserting a Task record (as if that user has created this Task through UI).

 

Here’s my problem: I need to insert a Task record by assigning a Default RecordType to be what is defined in the users Profile for a Task.

 

In other words, I need to (somehow) get a Task Default RecordTypeId for a particular User (whose User.Id is known).

 

Intuitively, I feel this should not be tough to accomplish (as I’m definitely not the first who is inserting a Task for a known user), but being fairly new to SalesForce I can not figure out how to make a connection between a User.Id and the location where a Task Default RecordType for a Profile is stored...

 

Any ideas guys?..

 

Thanks!

 

-Alex

 

kevinbnpowerkevinbnpower
You need to be more specific, by default, a task doesn't have a RecordType..

Alex_MAlex_M

Yep, not a problem.. Let me clarify:

 

Say we have 3 record types on Task:

 

1)       MyTaskRecordType1

2)       MyTaskRecordType2

3)       MyTaskRecordType3

 

Then, we have a Profile (let’s call it MySecurityProfile) which is setup to default to MyTaskRecordType2 anytime a new Task is created.

 

Now, we have a user MyUser who is assigned to MySecurityProfile. So, when MyUser creates a new Task record via UI, the Record Type is automatically defaulted to MyTaskRecordType2

 

 

In the Apex trigger I can get most variables populated from XML to assign correct values. I have the User.Id and can get to Profile. But I can't figure out how to get from Profile to where the default Record Type for Task is stored...

 

So, knowing that the user is MyUser and being able to get to MySecurityProfile, how can I find out that the default Record Type for Task is MyTaskRecordType2???

 

Task tsk =

new Task

(

WhoId             = strContactId,

WhatId            = strOpportuniyId,

OwnerId           = strUserId,

Subject           = strSubject,

Description       = strActivityDescription,

RecordTypeId      = ???

);

                       

insert tsk;

 

 

I hope this is specific enough, but please let me know if I can clarify further…

 

Thanks!

 

-Alex