A portal is not stored in one place. The metadata (Apex, static resources, VisualForce pages, block definitions) ships with the package, but the actual portals, their pages, and the page and form content are data. Page content, including every form built in the page builder, is stored as Salesforce Files (ContentVersions) linked to the Page__c record, not in fields. A metadata deploy or a package install moves none of it.
Because of this, moving a portal between orgs or sandboxes is a two part data load:
Web_Portal__c, then Page__c, then reconnect the portal to its home and 404 pages.This article covers both parts and the order they must run in. For the underlying schema see Object model and data dictionary. For how content is compiled and stored see Publishing pages.
Not everything is data. Get the platform layer in place first, then load data on top of it.
| Layer | How it moves | Notes |
|---|---|---|
| Apex, static resources, VisualForce pages | Package install or metadata deploy | Do this first. Nothing below works without it. |
Portal_Block__mdt, Google_Service_Auth__mdt |
Metadata deploy (custom metadata) | Block palette and push credentials. Deploy, do not data load. |
Portal__c (custom setting) |
Metadata deploy or manual re-entry | Org, profile, user level config. Not a transactional object. |
Web_Portal__c, Page__c |
Data load (this article) | The portal container and its pages. |
ContentVersion files (Template.b3p, Template_html.b3p) |
Data load (this article) | The page and form content. The main event. |
Contact (portal users), Web_Event__c, Push_Message__c |
Usually not migrated | Users and activity history are org specific. See the note at the end. |
This article assumes the platform layer is already in the target org. It only covers the data load.
When a page is saved in the builder, the builder writes two Files against the Page__c record rather than into fields:
Template.b3p: the editable page model (the builder configuration).Template_html.b3p: the compiled html, css, and js the runtime actually renders.Both are gzip plus base64 compressed. A form is not a separate object. Forms are assembled inside a page from field building blocks, so a form's fields, layout, and submit configuration are all part of that page's Template.b3p and Template_html.b3p. Migrate the page files and you migrate the form.
At render time the runtime finds a page's content by matching on the file title and the linked record, not by ID:
SELECT Id, FileType, PathOnClient, CreatedDate, ContentSize
FROM ContentVersion
WHERE ContentDocumentId = :docIdOfLinkedFile
AND IsLatest = true
where the document is found through a ContentDocumentLink whose ContentDocument.Title equals Template.b3p (or Template_html.b3p) and whose LinkedEntityId is the page record.
This is the rule that makes migration work. In the target org each migrated Page__c must end up with files titled exactly Template.b3p and Template_html.b3p linked to it. The record IDs will be different in the target org; the titles must be identical. Get the titles and the links right and the runtime finds the content regardless of new IDs.
Two things make the record load non trivial.
First, IDs change across orgs. Every reference has to be remapped. The clean way is to migrate a stable key alongside the record, so the tool can resolve the new parent for you.
Second, Web_Portal__c and Page__c reference each other:
Page__c.Web_Portal__c points up to the portal.Web_Portal__c.Home_Page__c and Web_Portal__c.Page_404__c point back down to specific pages.You cannot insert either side with all lookups populated in one pass. Break the cycle by loading in this order:
Web_Portal__c with the home and 404 lookups left blank.Page__c with Web_Portal__c populated (resolved from the portal you just inserted).Web_Portal__c to set Home_Page__c and Page_404__c now that the pages exist.Cross org relationship mapping is far easier if each record carries a stable key the loader can match on. If your package build allows it, add a temporary text external ID field (for example Migration_Key__c) to Web_Portal__c and Page__c, populate it in the source, and use upsert on that field in the target. Data Loader then resolves parent references for you and the load is idempotent, so a re run updates rather than duplicates.
If you cannot add a field, you can map on the record Name instead, provided names are unique within the portal, or keep an old ID to new ID mapping file by hand between steps. The steps below note both.
The examples use Data Loader because most admins have it and it handles Files, but the same queries work with the sf CLI or any ETL tool.
Portal:
SELECT Id, Name,
b3p__Branding_Resource_Name__c,
b3p__PWA_Short_Name__c, b3p__PWA_Description__c,
b3p__PWA_Start_URL__c, b3p__PWA_Theme_Color__c,
b3p__PWA_BG_Color__c, b3p__PWA_Status_Bar_Type__c,
b3p__PWA_Viewport__c,
b3p__Home_Page__c, b3p__Page_404__c
FROM b3p__Web_Portal__c
WHERE Id = 'a0X...sourcePortalId'
Pages:
SELECT Id, Name, b3p__Web_Portal__c,
b3p__Title__c,
b3p__Guest_User_Accessible__c,
b3p__Disable_Caching__c,
b3p__Sub_Template__c
FROM b3p__Page__c
WHERE b3p__Web_Portal__c = 'a0X...sourcePortalId'
Keep the source Home_Page__c and Page_404__c values from the portal export; you will need them in step 4.
Insert the Web_Portal__c row. Blank out b3p__Home_Page__c and b3p__Page_404__c for this insert; the pages do not exist yet. Also blank b3p__Emulated_Contact__c unless you are migrating that Contact separately.
Record the new portal ID (Data Loader writes a success file with the new IDs). If you added Migration_Key__c, this mapping is automatic on the next step.
Map b3p__Web_Portal__c on every page row to the new portal ID from step 2 (or upsert on Migration_Key__c and let Data Loader resolve it).
Keep the Data Loader success file. It gives you the old page ID to new page ID mapping, which you need for both the portal update in step 4 and the file relink in part two.
Update the Web_Portal__c row. Set b3p__Home_Page__c and b3p__Page_404__c to the new page IDs, translated from the source values you kept in step 1 using the page mapping from step 3.
At this point the records exist and are wired together, but every page is still blank because no content has been loaded.
Now move the files. For each page you are recreating its Template.b3p and Template_html.b3p as new Files in the target and linking them to the new page record.
First find the documents linked to the source pages:
SELECT ContentDocumentId, LinkedEntityId,
ContentDocument.Title,
ContentDocument.LatestPublishedVersionId
FROM ContentDocumentLink
WHERE LinkedEntityId IN ('a00...srcPage1', 'a00...srcPage2')
AND ContentDocument.Title IN ('Template.b3p', 'Template_html.b3p')
Then export the latest version content for those documents:
SELECT Id, ContentDocumentId, Title, PathOnClient,
VersionData, FileExtension
FROM ContentVersion
WHERE ContentDocumentId IN ('069...doc1', '069...doc2')
AND IsLatest = true
Data Loader exports VersionData as a separate file per row and puts the file path in the CSV. Keep that export folder intact; the insert reads from it.
Insert into ContentVersion in the target org. For each row set:
| Field | Value |
|---|---|
Title |
Exactly Template.b3p or Template_html.b3p. Do not change this. |
PathOnClient |
Same as source (for example Template.b3p). Drives the file extension. |
VersionData |
The exported version data for that row. |
Do not set ContentDocumentId. Leaving it blank makes each insert create a new ContentDocument in the target, which is what you want. Setting FirstPublishLocationId to the new page ID will both create the document and link it in one step, and if you do that you can skip step 7 for those rows.
Keep the success file. You now have a mapping from source document to new ContentVersion ID and, through it, the new ContentDocumentId.
If you did not use FirstPublishLocationId, create the ContentDocumentLink rows that attach each new document to its new page. This is the step that makes the runtime able to find the content.
Build a CSV that joins:
ContentDocumentId (from step 6),Insert into ContentDocumentLink:
| Field | Value |
|---|---|
ContentDocumentId |
New document ID from step 6. |
LinkedEntityId |
New Page__c ID from step 3. |
ShareType |
I |
Visibility |
AllUsers |
ShareType = I and Visibility = AllUsers match what the product sets when it saves and shares a template. Guest users must be able to read the file, so AllUsers visibility is required, not optional.
Confirm each new page has both files linked with the right titles:
SELECT LinkedEntityId, ContentDocument.Title,
ContentDocument.LatestPublishedVersionId
FROM ContentDocumentLink
WHERE LinkedEntityId IN ('a00...newPage1', 'a00...newPage2')
AND ContentDocument.Title IN ('Template.b3p', 'Template_html.b3p')
ORDER BY LinkedEntityId
Every migrated page should return two rows, one titled Template.b3p and one titled Template_html.b3p. Then open the portal in the target org. Pages, and any forms on them, should render.
| Step | Object | Operation | Key point |
|---|---|---|---|
| 1 | export | Query | Keep source home and 404 page IDs. |
| 2 | Web_Portal__c |
Insert | Blank the home, 404, and emulated contact lookups. |
| 3 | Page__c |
Insert | Point Web_Portal__c at the new portal. Keep the ID mapping. |
| 4 | Web_Portal__c |
Update | Set home and 404 to the new page IDs. |
| 5 | export | Query | ContentDocumentLink then ContentVersion, IsLatest = true. |
| 6 | ContentVersion |
Insert | Correct Title, blank ContentDocumentId, include VersionData. |
| 7 | ContentDocumentLink |
Insert | Link new doc to new page, ShareType = I, Visibility = AllUsers. |
| 8 | verify | Query | Two files per page, titled exactly. |
ContentDocument.Title. If a title is not exactly Template.b3p or Template_html.b3p, that page renders blank even though the file is attached.Visibility other than AllUsers. The page then fails to load content for guests but may look fine when you preview as an internal user.ContentDocumentId always creates new documents. If a migration is re run, either clear the previously loaded files first or drive the whole thing with an external ID and upserts so it stays idempotent.This procedure moves the portal definition and its content only. It deliberately leaves behind:
Contact records, their Temporary_Password__c access codes, and Disabled_Portal_User__c state are org specific. Migrate them separately only if the target is meant to serve the same users.Web_Event__c (including push device registrations and their FCM tokens) and Push_Message__c are runtime history tied to the source org and its Firebase project. Do not carry them across.Portal__c custom setting values and the Google_Service_Auth__mdt push credentials are platform configuration; set them in the target through metadata or by hand. See Configuration reference.