Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

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

share|improve this question

1 Answer 1

up vote 4 down vote accepted

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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