Custom components: creation and registration

Custom components: creation and registration

You can add your own draggable components to the builder without changing the managed package. A custom component is a web component you publish as a static resource, plus a Portal_Block__mdt custom metadata record that tells the builder how to present and configure it.

The two pieces

  1. A web component. Any custom element that renders itself, published in a static resource with an index.js that registers the element (for example customElements.define('my-widget', ...)). LWC OSS components are exposed through their CustomElementConstructor, exactly like the standard components.
  2. A Portal Block record. A b3p__Portal_Block__mdt record that points at the resource and tag and declares the editable attributes.

Step 1: build and publish the component

Write a self contained web component. Read runtime context from window.globals (siteUrl, sessionKey, userType, editor). See Technical architecture and request flow. Build it into a Salesforce static resource whose top level index.js registers the custom element. Deploy the static resource to the org.

Step 2: create the Portal Block record

Create a Portal_Block__mdt record. Key fields:

Field Value
Label The palette label
DeveloperName Used to derive the block and component type names
Category__c Interactions, Onboarding, Compliance, Data, UI, or UX
Web_Component_Tag__c The custom element tag, for example my-widget
JS_Resource__c The static resource name that contains the component index.js
Traits_JSON__c 3B Portals trait config describing the editable attributes
Order__c Position in the palette
Load_Immediately__c Check for libraries or shared code that must load first
Draggable__c, Droppable__c, Editable__c, Highlightable__c, Removable__c, Stylable__c 3B Portals component flags
Description__c An AI description so the AI builder can use the block
Is_Deprecated__c Check to hide from the palette

For a simple markup only block, leave Web_Component_Tag__c and JS_Resource__c empty and put raw HTML in HTML__c instead.

Traits JSON

Traits_JSON__c is a JSON array of 3B Portals traits that becomes the properties panel for the block. Each trait name maps to the kebab case HTML attribute your component reads. Example:

[
    { "type": "text", "name": "title", "label": "Title" },
    { "type": "text", "name": "record-id", "label": "Record Id", "value": "{{contactUser.Id}}" },
    { "type": "key-value", "name": "component-params", "label": "Parameters" }
]

Every registered component also supports conditional display. Trait values can be merge tags, for example {{contactUser.Id}} or {{record.Name}}.

How registration works

When the builder opens, it:

  1. Registers the managed blocks (chart, screen flow, iframe, custom LWC, sub template).
  2. Reads every non deprecated Portal_Block__mdt record, ordered by Order__c.
  3. For each record with a Web_Component_Tag__c, it registers a 3B Portals component type named <DeveloperName>-component using the tag, mapping the boolean flags to 3B Portals options, and building traits from Traits_JSON__c. It then adds a palette block <DeveloperName>-block that drops that component type.
  4. For records with only HTML__c, it adds a block that inserts the raw markup.
  5. Each block is also added to an AI block catalogue so the AI builder can use it.

Recover components shown as Text

From 12.0.0, the builder waits for custom block registration before opening a saved page. It also repairs elements saved as text or without a component type when their tag matches a registered component.

If a custom component appeared as Text with missing settings in an older version, open the page in the upgraded builder and save it once. The repair preserves saved attributes, so you do not need to delete and add the component again. If settings are still missing, check that the Portal Block record is not deprecated and that Web_Component_Tag__c matches the saved element's tag.

How the component renders

Working with offline portals

If the portal has offline support enabled, a custom component that calls Apex should opt in to caching and background sync so it behaves like the standard components. In short: post to the router REST endpoint with the session key in the body, add an X-Portal-Cache-Key header to reads you are happy to serve from a device cache, add X-Portal-Sync: 1 to writes that are safe to send later, and listen for background refreshes and replayed writes.

A component that does none of this still works. Its reads simply are not cached and its writes fail while the device is offline, as before.

The headers, request and response examples, the broadcast channel and the events are all in Component caching and offline API.

Practical checklist