experience-ui-bundle-file-upload-generate

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 pro

By forcedotcom · 4,873 installs

npx skills add forcedotcom/sf-skills --skill experience-ui-bundle-file-upload-generate

Source repository · Upstream listing

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 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 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 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 3. Build your custom UI The package provides the backend — you build the frontend. Here's a minimal example: 4. Track upload progress The onProgress callback fires multiple times for each file as it moves through stages: Status When Progress Value "pending" File queued for upload 0 "uploading" Upload in progress (XHR) 0 100 (percentage) "processing" Creating ContentVersion (if recordId provided) 0 "success" Upload complete 100 "error" Upload failed 0 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: 6. Link to current user (special case) If the user wants to upload files to their own profile or personal library: API Reference upload(options) Main upload API that handles complete flow with progress tracking. Returns: Promise<FileUploadResult[] createContentVersion(file, contentBodyId, recordId) Manually create a ContentVersion record from a previously uploaded file. 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. Returns: Current user ID Common UI patterns File input with button Drag and drop zone Build your own dropzone using native events: Progress bar 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