Technical architecture and request flow

Technical architecture and request flow

This article is for developers extending a portal with their own components or integrations. It covers what a portal is made of, how a component calls Apex, and the runtime context a component can read.

What a portal is made of

3B Portals is a managed package with the namespace b3p. A portal is rendered by three packaged apps, each delivered as a static resource and served from a Visualforce page.

App Static resource Served from Purpose
Portal runtime Portal Portal.page (<x-portal>) Renders published pages for portal users, including the offline worker.
Page builder PortalBuilder PortalBuilder.page (<x-builder>) The visual builder. Opened from the Builder button on a Page record, or from a Web Portal record.
Standard components StandardComponents Loaded by the runtime and the builder Chart, form field, iframe, login, screen flow and custom LWC host components.

Your own components sit alongside these. Each is a web component in a static resource, registered as a builder block through a b3p__Portal_Block__mdt record. See Custom components: creation and registration.

Whether navigation re-renders in place or reloads the page follows the Portals_are_SPA__c setting. See the Configuration reference.

Calling Apex: the request envelope

Every call from a portal to Salesforce uses the same envelope. Post it as JSON to the router REST endpoint on the Site domain:

POST https://<your-site-domain>/services/apexrest/b3p/GlobalRemotingRouter/
Content-Type: application/json
{
    "controllerName": "b3p.Portal",
    "endp": "getPages",
    "sessionKey": "<portal-session-key>",
    "pageOrPortalName": "MyPortal"
}
Key Purpose
controllerName The namespaced Apex class that handles the request, for example b3p.Portal.
endp The action to run on that class.
sessionKey The portal user's session key. This is what identifies the user.
any other key Passed to the action as a parameter.

Send no Authorization header for guest traffic. The sessionKey in the body identifies the portal user.

Response shape

The HTTP body is a JSON string whose content is the envelope JSON, so parse it twice:

const envelope = JSON.parse(JSON.parse(await response.text()));

The envelope carries:

Field Meaning
success true when the action completed.
statusCode The status of the call.
statusType The status category.
message A readable message, set on errors.
responseObject The action's result.
queued Present when offline support is enabled. true means the write was queued on the device.

Example:

{
    "success": true,
    "queued": false,
    "responseObject": { "records": [{ "Id": "<record-id>", "Name": "Acme" }] }
}

Treat success: false as an error and show message.

Headers for caching reads and queueing writes on offline portals, plus a complete fetch helper, are in Component caching and offline API.

Your own Apex classes

A class you call from a custom component implements System.Callable. The endp value arrives as the action name and the whole request body as the arguments map:

public with sharing class MyWidgetController implements System.Callable {
    public Object call(String action, Map<String, Object> args) {
        switch on action {
            when 'getSummary' {
                return getSummary((String) args.get('sessionKey'));
            }
            when else {
                throw new IllegalArgumentException('Unknown action ' + action);
            }
        }
    }
}

Never trust a Contact id sent by the browser. Resolve the user from the sessionKey through b3p.PortalSession and act as the Contact it returns. See Verifying a session from another package.

Runtime context: window.globals

The host page injects a window.globals object before your component loads. Custom components can rely on these fields:

Field Meaning
siteUrl The base URL of the Site. Use it to build the router endpoint.
sessionKey The current portal user's session key. Send it in the request body.
userType The Salesforce user type the page is running as, for example a guest user.
editor true when the component is rendered in the builder canvas, false on a published page. Use it to show placeholder content while editing.

Other fields on window.globals are internal to the packaged apps and can change between releases. Do not depend on them.

const endpoint = `${window.globals.siteUrl}/services/apexrest/b3p/GlobalRemotingRouter/`;

if (window.globals.editor) {
    this.showPlaceholder = true;
}

Data access

Portal users are Contacts, not Salesforce users, so the data a page shows is controlled by how the page and its components are configured. Scope every component's filters to the signed-in Contact, and grant the guest profile only what your pages need. See Security hardening checklist and Permission sets and access model.