0

We are currently building a page layout renderer for an offline application that would allow end-user to create records and then sync the data once they get access to internet again.

We need to support the following:

  • Page Layout Rendering
  • Support FLS
  • Custom Labels / Translations

I investigated at the new ui-api and it seems like it would tick all the boxes, however, it is geared towards online apps and seems like it would not be viable for an offline-first app.

Second option I've been looking into is sticking with what the Metadata API has to offer, by:

  • Querying Page Layouts individually + their mapping
  • Querying the SObject Describe for SObject and Field Describes
  • Query Custom Labels
  • Query translations

One thing that seems to missing is access to the aggregated Field Level Security. Should a field be visible on the UI? Is it read only? Is it updateable? This is available in Apex using the DescribeFieldResult.isAccessible(), but when querying it via the metadata API, it seems to exclude isUpdateable, isAccessible and isCreateable...

What are our options to attain this? I feel like our options would be to pull all the Permission Sets / Profiles and merge their settings together, or maybe have an Apex Rest API that would spit out DescribeFieldResult exposed in Apex...

How can this be achieved (and as friction-less as possible)?

0

The Metadata API is a Bad Idea. It requires permissions that a normal user should not have.

You should probably use Describe SObject resource to get the relevant information. It includes field labels, picklist values (including translations), field accessibility for the user, and more. From there, you'll need to spend an additional request to get the layouts per record type (see recordTypeInfos), but that should give you enough to at least render a full UI and provide basic edit capabilities.

The UI API also kind of provides this same information, which for practical purposes, you could consider cacheable, it just takes a few extra API calls. Also, remember you can use the Batch resource to perform up to 25 retrieves in bulk to save API calls.

The REST documentation specifically mentions that you need not retrieve all the time; you can use the If-Modified-Since header to figure out if any changes have occurred since the last cache update.

It should also be noted that both the describe call and layout call return permissions and translations as it would be for the running user. No fields will appear that they cannot view, and he read-only flags will be set correctly based on the greater restrictions of either field level security or page layout limitations. These APIs are built to give you an accurate data model for the user.

| improve this answer | |
  • It does not seem like it includes isAccessible though. Is that intentional and how could I handle if a field should be visible in that page layout for a user? – jpmonette May 20 at 10:21
  • @jpmonette The describe and layout calls already take this in to account by excluding hidden fields, and marking a field as read-only if the profile or layout does not allow the field to be edited. – sfdcfox May 20 at 15:43

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.