6

Question: How should I determine which layout to render for an object?

From my research, I think this can be done by looking at the RecordTypeId for an object, and then querying the layouts to find a layout that has the same RecordTypeId (i.e. sobjects/event/describe/layouts.)

However, if this is the correct approach, multiple layouts can exist for a RecordType, so I am left unsure of how to find the correct layout to Render.

Sub-Question: Should I be using the RecordTypeId on the object to get to the layout, or perhaps use the user's profile to find which RecordType's they have access to, and go from there.

Note: I'm using version 31.0 of the REST API

5

You're on the right track; use the describe resource on the record (e.g. /vxx.x/sobjects/Object/describe/), and in that response, you'll see a section like this:

"recordTypeInfos": [
    {
        "available": true,
        "defaultRecordTypeMapping": false,
        "name": "<record-type-name>",
        "recordTypeId": "<record-type-id>",
        "urls": {
            "layout": "/services/data/v30.0/sobjects/Object/describe/layouts/<record-type-id>"
        }
    },
    ...

Find the record type ID that matches the one you got from retrieving the record, and call that layout function. The system will automatically determine which layout is correct for your record type, given the profile you are logged in with.

Also, if you need to know which record type the user has access to, just look at the "available" attribute. The "defaultRecordTypeMapping" element specifies if this profile is using this record type as the default.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.