Skip to content

About

No description, website, or topics provided.

Resources

Code of conduct

Contributing

Security policy

Stars

1 star

Watchers

0 watching

Forks

Latest commit

 

History

227 Commits

Folders and files

Salesforce Metadata Previewer

A VS Code extension for previewing Salesforce metadata files, backed by a host-agnostic preview engine SDK.

Features

  • 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.

Architecture

This project uses a Lerna monorepo with two packages:

  • @salesforce/metadata-preview-core: The host-agnostic engine and SDK. Hosts implement IPreviewStorage, IProjectFiles, and a getSourceConnection callback, then construct a PreviewEngine and call preview, markDirty, or deleteAll. 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-preview will be renamed to salesforcedx-metadata-previewer-vscode in a follow-up (out of scope for this milestone).

Development

Install dependencies:

npm install

Build all packages:

npm run compile

Watch mode for development:

npm run watch

Run tests:

npm test

Lint:

npm run lint

Clean build artifacts:

npm run clean

Package the extension:

npm run package

This creates a .vsix file that can be installed in VS Code.

Run the Extension

  1. Open this folder in VS Code
  2. Press F5 to start a new Extension Development Host
  3. Open a Salesforce project with metadata files
  4. 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.

Creating a New Plugin

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().

How the Preview Pipeline Works

PreviewEngine.preview({ filePath }) runs an orchestrator with three setup steps:

  1. GetOrCreateOrgStep: Finds an existing preview org via IPreviewStorage or creates one.
  2. DeployMetadataStep: Deploys project metadata to the org (skipped if record.isDeploymentDone === true).
  3. 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.).

About

No description, website, or topics provided.

Resources

Code of conduct

Contributing

Security policy

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages