0

We need to work with layouts, though Apex code failed with an error for non-admin users.

Error message:

[{"message":"sObject type 'Layout' is not supported.","errorCode":"INVALID_TYPE"}]

Rest call is:

/services/data/v51.0/tooling/query?q=select+FullName+FROM+Layout+where+Id+=+xxx

It would work with ViewAllData permissions but this is totally insecure.

We found out later that it will work if user will have ViewSetup (+ dependent ViewRoles) permission.

But this is not a solution for us to allow all users have View Setup permissions.

Is there any workaround or another more limited permission to give users an ability request Layout sObject from tooling API ?

2 Answers 2

1

If you just want to provide read-only access to layouts, use the regular REST describe calls.

You can get all layouts:

/services/data/vXX.X/sobjects/Global/describe/layouts/

Or layouts for a specific object:

/services/data/vXX.X/sobjects/Object/describe/layouts/

Or for a specific layout for a specific record type:

/services/data/vXX.X/sobjects/Object/describe/layouts/<recordTypeId>

Which will be returned appropriately depending on the user's Profile and Page Layout Record Type Assignment.

6
  • Thanks, yes /sobjects/Object/describe/layouts/ works for me, but I need to get a fullName from Layout to get fields (using Metadata.Operations.retrieve(Metadata.MetadataType.Layout, layoutNamesList);) Aug 13, 2021 at 14:17
  • @VitaliyMalyshev What exactly are you trying to do?
    – sfdcfox
    Aug 13, 2021 at 14:44
  • I want to get fields from Layout. For the layoutNamesList in a metadata function call above it could be first item from /sobjects/Object/describe/layouts response or some custom layout name Aug 13, 2021 at 15:05
  • 2
    @VitaliyMalyshev But why, exactly? Why can't you just use the describe call to get the layout you need?
    – sfdcfox
    Aug 13, 2021 at 15:33
  • Does describe layouts could provide all info I am gettings using Metadata? components -> layoutSections -> layoutColumns -> layoutItems -> fields Aug 14, 2021 at 10:15
0

You can retrieve the entire metadata of a page layout using the Metadata namespace (and its classes) natively in apex https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_metadata_supported_types.htm

3
  • Metadata API also requires Modify All permission which is the main concern in the question Oct 6, 2021 at 5:00
  • This is not the metadata api, it's a native apex class that exposes the metadata api. This was released a few years ago. Read the doc I linked, it's not the API! Oct 6, 2021 at 5:24
  • 1
    Nothing against you, you don’t need to yell (jk). I read “Metadata API” and thought you meant Metadata API. I guess a more proper name would be Metadata Class. Oct 6, 2021 at 5:32

You must log in to answer this question.

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