3

We have a number of picklists that are subsetted via task record types. I can pull these record type via a simple SOQL query:

SELECT Name, DeveloperName FROM RecordType WHERE SobjectType = 'Task'

To make this useful, via API how can I:

  1. Tell which record type has which values?
  2. Identify the task record type for a user? I think this can be done via Page Layouts but it's not clear how

  3. Set the record type when creating a task? I think this is not needed as the layout handles the assignment

3
  • There's something in the UI-API (based on REST) that you can utilize to fetch the picklist values based on record types. Refer to the documentation here.
    – Jayant Das
    Commented Jul 2, 2018 at 20:37
  • Thanks @JayantDas the UI API does not support the Task object unfortunately! Commented Aug 8, 2018 at 19:47
  • right you are, didn’t realize it, I had come across this during one of my tests.
    – Jayant Das
    Commented Aug 9, 2018 at 1:53

2 Answers 2

6
  1. The picklist-values-per-record-type issue is an old problem to which there's only recently a semi-decent solution. There's a number of ways to approach this, and if you're already using the API, the new UI API is probably the best way to go.
  2. You can use a variety of routes to access record type availability. Issuing a Describe API call to, e.g., /services/data/v43.0/sobjects/Opportunity/describe has keys available (for the running user's Profile) and defaultRecordTypeMappingunder each of the entries in the recordTypeInfos. The Metadata API also permits you to get record type availability and default record type information at the Profile level, but it's non-trivial. The Tooling API can theoretically also yield this information, although I wasn't immediately able to get the record type visibilities that way in Workbench. (Looks like others have had that issue too).
  3. This is the easiest, but it has nothing to do with the page layout. Just set the field RecordTypeId on the Task you're inserting to the Id of the desired record type.

Note that if the Profile has exactly one custom record type associated with it, that will be used automatically.

5
  • Thanks so much David! 1. Do you know of any issues using my suggestion below with the Tooling API? 2. Didn't know about that resource but it solves it! 3. I can't see this field in the documentation, is it hidden or undocumented and "just works" Commented Jul 2, 2018 at 20:43
  • Any object that has record types enabled will have a RecordTypeId field. it shows up as RecordType in the Object Manager. I don't see any issues with your use of the Tooling API, although I haven't tried that route myself - we know that picklist information can be accessed through that door.
    – David Reed
    Commented Jul 2, 2018 at 20:50
  • I forgot about going in through the Describe API, as you mentioned in your answer regarding picklist values - that's a far easier way than the Metadata API to get record type availability info. I've updated that.
    – David Reed
    Commented Jul 2, 2018 at 20:53
  • I checked the UI API and it does not yet support Task. The Tooling API does provide this, except it does not return custom field data! Commented Aug 8, 2018 at 20:20
  • Yes, this doesn't return any custom field data? Does anyone else know of an alternative solution?
    – Jay
    Commented Jan 3, 2020 at 22:06
2

Here's my findings so far, documented for future reference:

At first glance it seemed possible with the describe call on the Task object /services/data/v43.0/sobjects/Task/describe/layouts

This yields some useful information such as defaultRecordTypeMapping which I think can be used to answer question 2.

There is also a field named picklistsForRecordType yet this returns an empty array. Probably not yet available so we are out of luck there.

Next we can check the new Tooling API: /services/data/v43.0/tooling/sobjects/RecordType/{id} Here we seem to be in luck! There is a Metadata.pickListValues array that contains each picklist field on the Task object.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .