A VS Code extension for previewing Salesforce metadata files, backed by a host-agnostic preview engine SDK.
- Preview Salesforce Metadata: Right-click on supported metadata files (e.g.,
.app-meta.xml) and select "Preview in Org" to open them in your preview org. - Plugin-based Architecture: Extensible system for adding support for different metadata types.
- IDE-agnostic Core: The engine ships independently of VS Code; hosts implement a small set of interfaces and let the engine drive the rest.
- Smart Execution Prevention: Prevents multiple simultaneous preview operations with user-friendly feedback.
- Intelligent Caching: Automatically skips redundant deployments and permission set assignments for faster previews.
This project uses a Lerna monorepo with two packages:
@salesforce/metadata-preview-core: The host-agnostic engine and SDK. Hosts implementIPreviewStorage,IProjectFiles, and agetSourceConnectioncallback, then construct aPreviewEngineand callpreview,markDirty, ordeleteAll. Built-in metadata plugins (Custom App, Flow, FlexiPage, Custom Object, Apex Class, Agent, Permission Set) live here.salesforcedx-vscode-metadata-preview: The VS Code host. Adapters wire@salesforce/core(AuthInfo,StateAggregator,AuthRemover,PreviewOrgConfig) into the SDK contracts and register the editor commands and file watchers.
Note:
salesforcedx-vscode-metadata-previewwill be renamed tosalesforcedx-metadata-previewer-vscodein a follow-up (out of scope for this milestone).
Install dependencies:
npm installBuild all packages:
npm run compileWatch mode for development:
npm run watchRun tests:
npm testLint:
npm run lintClean build artifacts:
npm run cleanPackage the extension:
npm run packageThis creates a .vsix file that can be installed in VS Code.
- Open this folder in VS Code
- Press
F5to start a new Extension Development Host - Open a Salesforce project with metadata files
- Right-click on a supported metadata file (e.g.,
.app-meta.xml) and select "Preview in Org"
The extension will:
- Automatically create or reuse a preview org
- Deploy your metadata (only if not already deployed)
- Assign required permission sets (only if not already assigned)
- Open the metadata in your browser
Note: Multiple clicks are automatically prevented - if a preview is already in progress, subsequent clicks will show an info message.
To add support for a new metadata type, implement PreviewPlugin from @salesforce/metadata-preview-core:
import { PreviewPlugin, PluginMetadata, PluginOrgContext } from '@salesforce/metadata-preview-core';
export class MyMetadata implements PreviewPlugin {
readonly metadata: PluginMetadata = {
id: 'salesforce.myMetadata',
name: 'My Metadata Type',
version: '1.0.0',
description: 'Preview my metadata type',
author: 'Salesforce',
filePatterns: ['**/*.mytype-meta.xml'],
assignPermsets: false
};
async getMetadataUIURL(orgContext: PluginOrgContext, filePath: string): Promise<string> {
orgContext.logger.info('Generating preview URL', { filePath });
// Use orgContext.querySingleRecord(...) to fetch record data if needed.
// Return the relative Lightning path; the engine wraps it in a frontdoor URL.
return '/lightning/r/MyMetadata__c/recordId/view';
}
}Plugins receive their logger from orgContext.logger (the per-invocation handle). The engine tags it automatically with the plugin id (metadata.id), so logs are attributed per-plugin and concurrent engine instances never scramble each other's log routing.
Built-in plugins are registered in packages/metadata-preview-core/src/plugins/index.ts (getAllPlugins). In v1 all plugins ship inside the core package — there is no host-facing runtime registration API. To add support for a new metadata type, add a plugin to src/plugins/ and include it in getAllPlugins().
PreviewEngine.preview({ filePath }) runs an orchestrator with three setup steps:
- GetOrCreateOrgStep: Finds an existing preview org via
IPreviewStorageor creates one. - DeployMetadataStep: Deploys project metadata to the org (skipped if
record.isDeploymentDone === true). - AssignPermissionsStep: Assigns permission sets if the matched plugin requested them (skipped if
record.isPermsetAssignmentDone === true).
Each step's completion state is persisted on the PreviewOrgRecord via IPreviewStorage, so subsequent previews against the same org skip work that's already done. After setup, the engine builds a frontdoor URL through Org.create({ connection }).getFrontDoorUrl(...) and returns it; the host opens it however it likes (Simple Browser for VS Code, SSE event for Browser, etc.).