3

I have a component that dynamically replicates a page layout . Im querying the ProfileLayout object to get the layout JSON, this works fine when i run as a sys admin, but fails when executed as a non-admin, getting this response:

{"message":"sObject type 'ProfileLayout' is not supported.","errorCode":"INVALID_TYPE"}

this is the query:

string query = 'select Layout.Name from ProfileLayout where ProfileId = \'' + UserInfo.getProfileId() + '\'';

Is there any way to achieve this?

3
  • 2
    The tooling API is generally unsuitable for non-admins. Perhaps the UI API or REST API would be better suited to your needs?
    – sfdcfox
    Nov 15, 2018 at 15:53
  • I looked at the UI api but there doesn't seem to be a way to get the correct layout for the running user based on Profile/RecordType when creating a new record, its fine for an existing record as i can pass the record ID in
    – paul
    Nov 15, 2018 at 16:03
  • Have you explored the Apex Metadata class? It supports layouts, but I am not sure if it will support your use case. Nov 15, 2018 at 16:22

3 Answers 3

3

The describe call you're apparently looking for is:

/services/data/v43.0/sobjects/<ObjectName>/describe/layouts/<recordTypeId>

This will give you all the layout information need for a given record type and object type. This call is available for all users so long as they have any API access.

1
0

I used by mistake the wrong URL - /data/{apiVersion}/query?q='' instead of /data/{apiVersion}/tooling/query?q='', maybe this also applies to your case.

0

This works for me:

/services/data/v49.0/tooling/query?q=select+LayoutId,+RecordTypeId,+TableEnumOrId+from+ProfileLayout+where+ProfileId+=+'00e0p000000WhKwAAK'

Notice that the string /tooling is in the URL. Without this bit, it hits the error.

You must log in to answer this question.

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