Experience Ui Bundle File Upload Generate

by forcedotcome5164d94d751No license1K starsListed Oct 8, 2026Updated Oct 8, 2026Repository updated yesterday

MUST activate when the project contains a uiBundles/*/src/ directory and the task involves uploading, attaching, or dropping files. Use this skill when adding file upload functionality to a UI bundle app. Provides progress tracking and Salesforce ContentVersion integration. This feature provides programmatic APIs ONLY — build custom UI using the upload() API. ALWAYS use this instead of building file upload from scratch with FormData or XHR.

Instructions onlySoftware Development
AI-generated overview

Guides adding file upload to Salesforce UI bundle apps using the upload() API with progress tracking and ContentVersion linking.

What it does
This skill documents a workflow for adding file upload functionality to React UI bundle apps on Salesforce. It covers installing the file upload package, choosing among three upload patterns (basic upload, immediate record linking, and deferred linking after record creation), building custom UI such as file inputs and dropzones, tracking progress through the onProgress callback, cancelling uploads with AbortController, and linking files to the current user. It also provides an API reference for upload(), createContentVersion(), and getCurrentUserId(), plus troubleshooting guidance.
When to use it
Use it when a project contains a uiBundles/*/src/ directory and the task involves uploading, attaching, or dropping files. It is intended for adding file upload functionality to a UI bundle app, including upload-and-attach flows and create-record-with-attachments forms.
Requirements
Requires npm 7.0.0 or later to install the @salesforce/ui-bundle-template-feature-react-file-upload package, which pulls in @salesforce/ui-bundle and @salesforce/platform-sdk. A Salesforce org with appropriate ContentVersion permissions and CORS configuration is needed. The skill ships no scripts; it is instructions only.

File Upload API (workflow)

When the user wants file upload functionality in a React UI bundle, follow this workflow. This feature provides APIs only — you must build the UI components yourself using the provided APIs.

CRITICAL: This is an API-only package

The package exports programmatic APIs, not React components or hooks. You will:

  • Use the upload() function to handle file uploads with progress tracking
  • Build your own custom UI (file input, dropzone, progress bars, etc.)
  • Track upload progress through the onProgress callback

Do NOT:

  • Expect pre-built components like <FileUpload /> — they are not exported
  • Try to import React hooks like useFileUpload — they are not exported
  • Look for dropzone components — they are not exported

The source code contains reference components for demonstration, but they are not available as imports. Use them as examples to build your own UI.

1. Install the package

bash
npm install @salesforce/ui-bundle-template-feature-react-file-upload

Dependencies are automatically installed:

  • @salesforce/ui-bundle (API client)
  • @salesforce/platform-sdk (data SDK; the old @salesforce/sdk-data name is dead — see the experience-ui-bundle-salesforce-data-access skill)

2. Understand the three upload patterns

Pattern A: Basic upload (no record linking)

Upload files to Salesforce and get back contentBodyId for each file. No ContentVersion record is created.

When to use:

  • User wants to upload files first, then create/link them to a record later
  • Building a multi-step form where the record doesn't exist yet
  • Deferred record linking scenarios
tsx
import { upload } from "@salesforce/ui-bundle-template-feature-react-file-upload";
const results = await upload({  files: [file1, file2],  onProgress: (progress) => {    console.log(`${progress.fileName}: ${progress.status} - ${progress.progress}%`);  },});
// results[0].contentBodyId: "069..." (always available)// results[0].contentVersionId: undefined (no record linked)

Pattern B: Upload with immediate record linking

Upload files and immediately link them to an existing Salesforce record by creating ContentVersion records.

When to use:

  • Record already exists (Account, Opportunity, Case, etc.)
  • User wants files immediately attached to the record
  • Direct upload-and-attach scenarios
tsx
import { upload } from "@salesforce/ui-bundle-template-feature-react-file-upload";
const results = await upload({  files: [file1, file2],  recordId: "001xx000000yyyy", // Existing record ID  onProgress: (progress) => {    console.log(`${progress.fileName}: ${progress.status} - ${progress.progress}%`);  },});
// results[0].contentBodyId: "069..." (always available)// results[0].contentVersionId: "068..." (linked to record)

Pattern C: Deferred record linking (record creation flow)

Upload files without a record, then link them after the record is created.

When to use:

  • Building a "create record with attachments" form
  • Record doesn't exist until form submission
  • Need to upload files before knowing the final record ID
tsx
import {  upload,  createContentVersion,} from "@salesforce/ui-bundle-template-feature-react-file-upload";
// Step 1: Upload files (no recordId)const uploadResults = await upload({  files: [file1, file2],  onProgress: (progress) => console.log(progress),});
// Step 2: Create the recordconst newRecordId = await createRecord(formData);
// Step 3: Link uploaded files to the new recordfor (const file of uploadResults) {  const contentVersionId = await createContentVersion(    new File([""], file.fileName),    file.contentBodyId,    newRecordId,  );}

3. Build your custom UI

The package provides the backend — you build the frontend. Here's a minimal example:

tsx
import {  upload,  type FileUploadProgress,} from "@salesforce/ui-bundle-template-feature-react-file-upload";import { useState } from "react";
function CustomFileUpload({ recordId }: { recordId?: string }) {  const [progress, setProgress] = useState<Map<string, FileUploadProgress>>(new Map());
  const handleFileSelect = async (event: React.ChangeEvent<HTMLInputElement>) => {    const files = Array.from(event.target.files || []);
    await upload({      files,      recordId,      onProgress: (fileProgress) => {        setProgress((prev) => new Map(prev).set(fileProgress.fileName, fileProgress));      },    });  };
  return (    <div>      <input type="file" multiple onChange={handleFileSelect} />
      {Array.from(progress.entries()).map(([fileName, fileProgress]) => (        <div key={fileName}>          {fileName}: {fileProgress.status} - {fileProgress.progress}%          {fileProgress.error && <span>Error: {fileProgress.error}</span>}        </div>      ))}    </div>  );}

4. Track upload progress

The onProgress callback fires multiple times for each file as it moves through stages:

StatusWhenProgress Value
"pending"File queued for upload0
"uploading"Upload in progress (XHR)0-100 (percentage)
"processing"Creating ContentVersion (if recordId provided)0
"success"Upload complete100
"error"Upload failed0

Always provide visual feedback:

  • Show file name
  • Display current status
  • Render progress bar for "uploading" status
  • Show error message if status is "error"

5. Cancel uploads (optional)

Use an AbortController to allow users to cancel uploads:

tsx
const abortController = new AbortController();
const handleUpload = async (files: File[]) => {  try {    await upload({      files,      signal: abortController.signal,      onProgress: (progress) => console.log(progress),    });  } catch (error) {    console.error("Upload cancelled or failed:", error);  }};
const cancelUpload = () => {  abortController.abort();};

6. Link to current user (special case)

If the user wants to upload files to their own profile or personal library:

tsx
import {  upload,  getCurrentUserId,} from "@salesforce/ui-bundle-template-feature-react-file-upload";
const userId = await getCurrentUserId();await upload({ files, recordId: userId });

API Reference

upload(options)

Main upload API that handles complete flow with progress tracking.

typescript
interface UploadOptions {  files: File[];  recordId?: string | null; // If provided, creates ContentVersion  onProgress?: (progress: FileUploadProgress) => void;  signal?: AbortSignal; // Optional cancellation}
interface FileUploadProgress {  fileName: string;  status: "pending" | "uploading" | "processing" | "success" | "error";  progress: number; // 0-100 for uploading, 0 for other states  error?: string;}
interface FileUploadResult {  fileName: string;  size: number;  contentBodyId: string; // Always available  contentVersionId?: string; // Only if recordId was provided}

Returns: Promise<FileUploadResult[]>

createContentVersion(file, contentBodyId, recordId)

Manually create a ContentVersion record from a previously uploaded file.

typescript
async function createContentVersion(  file: File,  contentBodyId: string,  recordId: string,): Promise<string | undefined>;

Parameters:

  • file — File object (used for metadata like name)
  • contentBodyId — ContentBody ID from previous upload
  • recordId — Record ID for FirstPublishLocationId

Returns: ContentVersion ID if successful

getCurrentUserId()

Get the current user's Salesforce ID.

typescript
async function getCurrentUserId(): Promise<string>;

Returns: Current user ID

Common UI patterns

File input with button

tsx
<input type="file" multiple accept=".pdf,.doc,.docx,.jpg,.png" onChange={handleFileSelect} />

Drag-and-drop zone

Build your own dropzone using native events:

tsx
function DropZone({ onDrop }: { onDrop: (files: File[]) => void }) {  const handleDrop = (e: React.DragEvent) => {    e.preventDefault();    const files = Array.from(e.dataTransfer.files);    onDrop(files);  };
  return (    <div      onDrop={handleDrop}      onDragOver={(e) => e.preventDefault()}      style={{ border: "2px dashed #ccc", padding: "2rem" }}    >      Drop files here    </div>  );}

Progress bar

tsx
{  progress.status === "uploading" && (    <div style={{ width: "100%", background: "#eee" }}>      <div        style={{          width: `${progress.progress}%`,          background: "#0176d3",          height: "8px",        }}      />    </div>  );}

Decision tree for agents

User asks for file upload functionality:

  1. Ask about record context:

    • "Do you want to link uploaded files to a specific record, or upload them first and link later?"
  2. Based on response:

    • Link to existing record → Use Pattern B with recordId
    • Upload first, link later → Use Pattern A (no recordId), then Pattern C for linking
    • Link to current user → Use Pattern B with getCurrentUserId()
  3. Build the UI:

    • Create file input or dropzone (not provided by package)
    • Add progress display for each file (status + progress bar)
    • Handle errors in the UI
  4. Test the implementation:

    • Verify progress callbacks fire correctly
    • Check that contentBodyId is returned
    • If recordId was provided, verify contentVersionId is returned

Reference implementation

The package includes a reference implementation in src/features/fileupload/ with:

  • FileUpload.tsx — Complete component with dropzone and dialog
  • FileUploadDialog.tsx — Progress tracking dialog
  • FileUploadDropZone.tsx — Drag-and-drop zone
  • useFileUpload.ts — React hook for state management

These are NOT exported but can be viewed as examples. Read the source files to understand patterns for building your own UI.

Troubleshooting

Upload fails with CORS error:

  • Ensure the UI bundle is properly deployed to Salesforce or running on localhost
  • Check that the org allows the origin in CORS settings

No progress updates:

  • Verify onProgress callback is provided
  • Check that the callback function updates React state correctly

ContentVersion not created:

  • Verify recordId is provided to upload() function
  • Check that the record ID is valid and exists in the org
  • Ensure user has permissions to create ContentVersion records

Files upload but don't appear in record:

  • Verify recordId is correct
  • Check that ContentVersion was created (look for contentVersionId in results)
  • Confirm user has access to view files on the record

DO NOT do these things

  • Build XHR/fetch upload logic from scratch — use the upload() API
  • Try to import <FileUpload /> component — it's not exported
  • Try to import useFileUpload hook — it's not exported
  • Use third-party file upload libraries when this feature exists
  • Skip progress tracking — always provide user feedback
  • Ignore errors — always handle and display error messages

Source and attribution

Source:forcedotcom/sf-skillsinskills/experience-ui-bundle-file-upload-generateat commite5164d9

License: No license

Content belongs to its original authors. SourceWeft indexes it from a public repository.

Report or request removal

More from forcedotcom/sf-skills

Service Itsm Teams Itservice Configure

forcedotcom

Configure the "Set Up Salesforce IT Service" checklist for Microsoft Teams Employee Service (ITSM) — the employee side, covering app enablement, marketplace install guidance, user access assignment, and Digital Experience Site selection. Use this for: 'turn on Salesforce IT Service', 'set up IT Service on Teams', 'assign Teams for Employee permission set', 'give employees access to Teams for Employee Service', 'manage user access for Teams ITSM', 'grant users the permission sets needed for Teams Employee Service', 'select a digital experience site for Teams', 'install Salesforce IT Service app on Teams', or any request to complete the IT Service half of the Teams ITSM Go page checklist (including the Manage User Access step). DO NOT TRIGGER for the base Teams Salesforce Go page toggle or Azure/Entra app setup (service-itsm-teams-configure) or for the IT Desk/fulfiller half of the checklist (service-itsm-teams-itdesk-configure).

Awaiting classification1Kupdated yesterday

Service Itsm Teams Coordinate

forcedotcom

End-to-end autopilot orchestrator for setting up Microsoft Teams integration in Salesforce Service Cloud ITSM — runs the whole flow (enable the Teams for Employee Service Go feature, register the Microsoft Entra app, populate Named Credentials, configure the IT Desk and IT Service checklists, turn on Swarming, and optionally embed the Agentforce agent) in one continuous pass, stopping only at the points a human must act. Use when the user asks to set up Microsoft Teams for ITSM end to end, 'set up teams for it service', 'do the whole teams itsm setup', 'configure microsoft teams for employee service', or wants a guided Teams ITSM walkthrough. Delegates each stage to a specialized child skill while driving the sequence itself. DO NOT TRIGGER when the user asks to enable Teams alone, configure just the IT Desk or IT Service checklist alone, or enable Swarming alone — delegate directly to the specific child skill in those cases.

Awaiting classification1Kupdated yesterday

Service Itsm Teams Itdesk Configure

forcedotcom

Configure the "Set Up Salesforce IT Desk" checklist for Microsoft Teams Employee Service (ITSM) — the fulfiller/agent side, covering app enablement, marketplace install guidance, user access assignment, and Swarming collaboration-tool setup. Use this for: 'turn on Salesforce IT Desk', 'set up IT Desk on Teams', 'assign Teams for IT Desk permission set', 'set Teams as collaboration tool for swarming', 'install Salesforce IT Desk app on Teams', or any request to complete the IT Desk half of the Teams ITSM Go page checklist. DO NOT TRIGGER for the base Teams Salesforce Go page toggle or Azure/Entra app setup (service-itsm-teams-configure) or for the IT Service/employee half of the checklist (service-itsm-teams-itservice-configure).

Awaiting classification1Kupdated yesterday

Service Itsm Teams Debug

forcedotcom

Diagnoses failing Microsoft Teams for Employee Service (ITSM) setups by running pass/fail configuration checklists against a Salesforce org.

DevOps & Cloud1Kupdated yesterday

Service Itsm Teams Employee Agent Configure

forcedotcom

Configure the embedded Agentforce Employee Agent so it replies inside the Microsoft Teams ITSM custom client ('Salesforce Employee Assist' / 'Ask AI Agent'). Use this for: 'set up employee agent in Teams', 'embed Agentforce agent in Teams', 'make the IT Service Employee Agent reply in Teams', 'Teams Ask AI Agent not responding', 'agent joins then leaves without replying', 'configure MIAW deployment for Teams employee agent', 'Teams embedded messaging agent setup'. Builds the whole stack headlessly (zero Setup-UI clicks): the Web messaging channel with User Verification ON, the Enhanced Chat User Verification Key Set (JWKS_URL) it requires, the Teams_AgentForce custom-client deployment, the routing flow to the agent, and the Agent Access permission set that lets the portal user reach the agent. DO NOT TRIGGER for enabling the Teams feature Salesforce Go page toggle (service-itsm-teams-configure) or for configuring notification preferences.

Awaiting classification1Kupdated yesterday

Service Itsm Swarming Configure

forcedotcom

Enables the Salesforce Swarming ITSM feature and sets the collaboration tool to Teams via Connect API calls.

DevOps & Cloud1Kupdated yesterday