Skip to content
| Marketplace
Sign in
Visual Studio Code>Programming Languages>Salesforce LWC & Apex Snippets ProNew to Visual Studio Code? Get it now.
Salesforce LWC & Apex Snippets Pro

Salesforce LWC & Apex Snippets Pro

Shubham Prajapati

|
1 install
| (0) | Free
Comprehensive code snippets for Salesforce Lightning Web Components (LWC) and Apex — 170+ snippets covering @wire, @api, @AuraEnabled, LDS, LMS, NavigationMixin, triggers, tests, batch, queueable, callouts and more.
Installation
Launch VS Code Quick Open (Ctrl+P), paste the following command, and press enter.
Copied to clipboard
More Info

Salesforce LWC & Apex Snippets Pro

A comprehensive VS Code snippet extension for Salesforce Lightning Web Components (LWC) and Apex development.


📦 Installation

From VSIX (local)

code --install-extension salesforce-lwc-apex-snippets-1.0.0.vsix

From VS Code Marketplace

Search for "Salesforce LWC & Apex Snippets Pro" in the Extensions panel.


🚀 Snippet Reference

LWC — JavaScript (lwc-*)

Prefix Description
lwc-component Full component scaffold (lifecycle, @api, @track, handlers)
lwc-component-minimal Minimal component class
lwc-component-record Component with recordId + objectApiName
lwc-api @api public property
lwc-api-method @api public method
lwc-api-getter-setter @api getter/setter pattern
lwc-track @track reactive property
lwc-wire-apex @wire Apex method with data/error handler
lwc-wire-getrecord @wire getRecord with field import
lwc-wire-getobjectinfo @wire getObjectInfo
lwc-wire-picklist @wire getPicklistValues
lwc-wire-relatedlist @wire getRelatedListRecords
lwc-wire-currentuser @wire current user info
lwc-apex-imperative Imperative Apex call (.then().catch())
lwc-apex-async Imperative Apex call (async/await)
lwc-toast Show Toast notification
lwc-toast-helper Reusable _showToast() helper
lwc-event-dispatch Dispatch CustomEvent
lwc-event-handle Handle CustomEvent
lwc-lds-create createRecord (LDS)
lwc-lds-update updateRecord (LDS)
lwc-lds-delete deleteRecord (LDS)
lwc-refresh-apex refreshApex()
lwc-nav-mixin NavigationMixin component
lwc-nav-record Navigate to record page
lwc-nav-list Navigate to list view
lwc-nav-new Navigate to new record
lwc-nav-url Navigate to web URL
lwc-nav-named Navigate to named page
lwc-nav-generate-url Generate URL without navigating
lwc-lms-publish LMS publisher
lwc-lms-subscribe LMS subscriber
lwc-reduce-errors _reduceErrors() helper
lwc-debounce Debounce utility
lwc-label Import custom label
lwc-permission Import custom permission
lwc-static-resource Load static resource script/style
lwc-connected connectedCallback
lwc-disconnected disconnectedCallback
lwc-rendered renderedCallback with init guard
lwc-error-callback errorCallback
lwc-query this.template.querySelector
lwc-query-all this.template.querySelectorAll
lwc-refs this.refs.refName
lwc-pubsub-register Legacy PubSub register/unregister

LWC — HTML (lwc-*)

Prefix Description
lwc-template Full template (spinner + error + data)
lwc-template-minimal Minimal <template> wrapper
lwc-if if:true conditional
lwc-if-false if:false conditional
lwc-if-else lwc:if / lwc:else (API v55+)
lwc-if-elseif lwc:if / lwc:elseif / lwc:else chain
lwc-foreach for:each list rendering
lwc-iterator iterator with first/last
lwc-spread lwc:spread attribute spreading
lwc-ref lwc:ref template reference
lwc-card lightning-card
lwc-button lightning-button
lwc-button-icon lightning-button-icon
lwc-input lightning-input
lwc-combobox lightning-combobox
lwc-datatable lightning-datatable
lwc-record-form lightning-record-form
lwc-record-edit-form lightning-record-edit-form
lwc-record-view-form lightning-record-view-form
lwc-spinner lightning-spinner with condition
lwc-modal Custom SLDS modal dialog
lwc-tabset lightning-tabset
lwc-accordion lightning-accordion
lwc-badge lightning-badge
lwc-pill lightning-pill
lwc-file-upload lightning-file-upload
lwc-formatted-text lightning-formatted-text
lwc-formatted-date lightning-formatted-date-time
lwc-formatted-number lightning-formatted-number
lwc-icon lightning-icon
lwc-tile lightning-tile
lwc-tree lightning-tree
lwc-progress lightning-progress-indicator
lwc-lookup lightning-lookup
lwc-map lightning-map
lwc-slds-grid SLDS Grid layout
lwc-slds-box SLDS box
lwc-slds-notification SLDS scoped notification
lwc-slot Default slot
lwc-slot-named Named slot

Apex (apex-*)

Prefix Description
apex-class Full class scaffold with JSDoc
apex-controller @AuraEnabled controller
apex-service Service layer class
apex-selector Selector/query class pattern
apex-domain Domain handler class
apex-aura-cacheable @AuraEnabled(cacheable=true) method
apex-aura-dml @AuraEnabled DML method
apex-aura-json @AuraEnabled JSON payload method
apex-soql SOQL with USER_MODE
apex-soql-bind SOQL with bind variable
apex-soql-subquery SOQL parent-child subquery
apex-soql-count SOQL COUNT aggregate
apex-soql-groupby SOQL GROUP BY aggregate
apex-soql-dynamic Dynamic SOQL
apex-soql-forupdate SOQL FOR UPDATE
apex-sosl SOSL search
apex-dml-insert DML insert with error handling
apex-dml-update DML update
apex-dml-upsert DML upsert with external ID
apex-dml-delete DML delete
apex-db-insert Database.insert allOrNone=false
apex-db-upsert Database.upsert allOrNone=false
apex-try try-catch-finally
apex-exception Custom exception class
apex-map-from-list Map<Id, SObject> from SOQL
apex-map-group Group list into Map<Id, List<SObject>>
apex-set-extract Extract Set from list field
apex-list-pluck Extract List of field values
apex-limits Governor limits debug
apex-future @future method
apex-queueable Queueable class
apex-schedulable Schedulable class
apex-batch Database.Batchable class
apex-batch-stateful Stateful Batchable with counters
apex-http-get HTTP GET callout
apex-http-post HTTP POST callout
apex-fls-read FLS check before read
apex-crud-check CRUD permission check
apex-strip-inaccessible Security.stripInaccessible
apex-describe-sobject Describe SObject
apex-describe-field Describe field
apex-picklist-describe Get picklist values via describe
apex-json-serialize JSON.serialize
apex-json-deserialize JSON.deserialize
apex-json-untyped JSON.deserializeUntyped
apex-string-utils String utility methods
apex-date-utils Date/DateTime utilities
apex-custom-setting Access Custom Setting
apex-custom-metadata Query Custom Metadata
apex-platform-event-publish Publish Platform Event
apex-wrapper Wrapper/DTO inner class
apex-paginator Paginated controller + wrapper
apex-email-send Send single email
apex-content-version Insert ContentVersion (file)

Apex Triggers (apex-trigger*)

Prefix Description
apex-trigger Trigger with handler delegation
apex-trigger-handler Full trigger handler class
apex-trigger-bypass Trigger bypass pattern
apex-trigger-field-changed Detect field change
apex-trigger-recursion Prevent recursion pattern
apex-trigger-bulkify Bulkified trigger pattern
apex-trigger-test Trigger unit test class

Apex Tests (apex-test*)

Prefix Description
apex-test-class Full test class scaffold
apex-test-setup @TestSetup method
apex-test-method @IsTest method with AAA pattern
apex-test-assert All assert methods
apex-test-start-stop Test.startTest() / stopTest()
apex-test-mock-http Mock HTTP callout
apex-test-bulk Bulk test with 200 records
apex-test-runAs System.runAs(user) test
apex-test-exception Test exception thrown
apex-test-factory TestDataFactory call pattern
apex-test-factory-class Full TestDataFactory class

Wire Adapters (wire-*)

Prefix Description
wire-getrecord-multi getRecord with multiple fields
wire-getrecord-handler getRecord with function handler
wire-getlistui getListUi
wire-getlookupinfos getLookupReferenceToObjectInfos
wire-getnavitems getNavItems
wire-getrelatedlistinfo getRelatedListInfo
wire-getrelatedlistsinfo getRelatedListsInfo (all)
wire-getrelatedlistcount getRelatedListCount
wire-mru-list MRU list via getListUi
wire-apex-reactive @wire Apex with reactive private property
wire-apex-tree @wire Apex returning tree data
wire-currentpageref CurrentPageReference
wire-getconnectedapps getConnectedApps

Navigation (lwc-nav-*)

Prefix Description
lwc-nav-app Navigate to Lightning App
lwc-nav-component Navigate to LWC/Aura component
lwc-nav-knowledge Navigate to Knowledge Article
lwc-nav-login Navigate to community login/logout
lwc-nav-flow Navigate to Flow with input variables
lwc-nav-report Navigate to Report
lwc-nav-dashboard Navigate to Dashboard
lwc-nav-related-list Navigate to record related list
lwc-nav-state Navigate with URL state params
lwc-nav-file Open file preview page
lwc-nav-open-url Generate URL and open in new tab
lwc-nav-back Navigate back / to home

Package Manifest

Prefix Description
sf-package Full package.xml scaffold
sf-package-types Single <types> block to add inside package.xml
sf-package-wildcard package.xml with wildcard * for all common metadata types

Custom Object

Prefix Description
sf-object Complete CustomObject metadata XML with all key properties

Custom Fields

Prefix Field Type
sf-field-text Text
sf-field-number Number
sf-field-currency Currency
sf-field-checkbox Checkbox
sf-field-date Date
sf-field-datetime DateTime
sf-field-picklist Picklist (with inline value set)
sf-field-multipicklist Multi-Select Picklist
sf-field-lookup Lookup relationship
sf-field-masterdetail Master-Detail relationship
sf-field-formula Formula field
sf-field-rollup Roll-Up Summary
sf-field-longtext Long Text Area
sf-field-richtext Rich Text Area (HTML)
sf-field-email Email
sf-field-phone Phone
sf-field-url URL
sf-field-geolocation Geolocation

Flow

Flow Scaffolds

Prefix Description
sf-flow Screen Flow scaffold
sf-flow-auto AutoLaunched Flow scaffold
sf-flow-trigger Record-Triggered Flow scaffold (with filter condition)

Flow Elements

Prefix Element
sf-flow-screen Screen element with a field
sf-flow-decision Decision (branch) with one outcome
sf-flow-assignment Assignment element
sf-flow-loop Loop element
sf-flow-getrecords Get Records
sf-flow-createrecords Create Records
sf-flow-updaterecords Update Records
sf-flow-deleterecords Delete Records
sf-flow-subflow Subflow with input/output assignments
sf-flow-action Action Call (Apex, email, quick action, etc.) with fault connector
sf-flow-error Custom Error element

Flow Resources

Prefix Resource
sf-flow-var-string String variable (input/output/collection toggles)
sf-flow-var-sobject SObject / Record variable
sf-flow-var-bool Boolean variable
sf-flow-constant Constant
sf-flow-texttemplate Text Template
sf-flow-formula Formula resource

Permission Sets

Prefix Description
sf-permset PermissionSet scaffold
sf-permset-object Object permissions block
sf-permset-field Field permission block
sf-permset-apex Apex class access block
sf-permset-vf Visualforce page access block
sf-permset-tab Tab visibility block
sf-permset-customperm Custom permission block

Profiles

Prefix Description
sf-profile Profile metadata scaffold

Layouts & Pages

Prefix Description
sf-layout Page Layout metadata scaffold
sf-flexipage FlexiPage (Lightning App Builder) scaffold

Workflow Rules

Prefix Description
sf-workflow-rule Workflow Rule with criteria and time trigger
sf-workflow-fieldupdate Workflow Field Update action
sf-workflow-emailalert Workflow Email Alert action

Other Metadata

Prefix Description
sf-validation Validation Rule
sf-recordtype Record Type with picklist values
sf-label Custom Label
sf-globalvalueset Global Value Set (shared picklist)
sf-cmdt-object Custom Metadata Type object definition
sf-cmdt-record Custom Metadata Type record XML
sf-customsetting Custom Setting (Hierarchy or List)
sf-namedcred Named Credential
sf-connectedapp Connected App with OAuth config
sf-reporttype Custom Report Type
sf-sharingrule-criteria Criteria-based Sharing Rule
sf-emailtemplate Email Template
sf-queue Queue with members and supported objects
sf-staticresource-meta StaticResource -meta.xml

Component & Class Metadata Files

Prefix Description
sf-apexclass-meta ApexClass-meta.xml
sf-apextrigger-meta ApexTrigger-meta.xml
sf-lwc-meta LightningComponentBundle-meta.xml with targets and properties
sf-aura-meta AuraDefinitionBundle-meta.xml

SFDX Project

Prefix Scope Description
sf-sfdx-project JSON sfdx-project.json scaffold

✅ Language Support

Language ID File Types
javascript *.js (LWC component JS)
html *.html (LWC templates)
apex *.cls, *.trigger
xml *.cls, *.trigger

Example Usage

Creating a new Custom Object with fields

  1. Create force-app/main/default/objects/Invoice__c/Invoice__c.object-meta.xml
  2. Type sf-object → expand → fill in label, plural label, sharing model
  3. Type sf-field-currency inside the same file (or in a separate field file) → expand → fill in field name

Building a Record-Triggered Flow

  1. Create a new .flow-meta.xml file
  2. Type sf-flow-trigger → expand the scaffold
  3. Add sf-flow-getrecords, sf-flow-decision, sf-flow-updaterecords elements
  4. Wire them via <targetReference> connectors

Setting up a Permission Set

  1. Create a new .permissionset-meta.xml file
  2. Type sf-permset → expand scaffold
  3. Add sf-permset-object blocks for each object
  4. Add sf-permset-field blocks for field-level security
  • Contact us
  • Jobs
  • Privacy
  • Manage cookies
  • Terms of use
  • Trademarks
© 2026 Microsoft