Skip to content

forcedotcom/sf-skills / plugins/builder/experience-lwc/skills/experience-lwc-generate

experience-lwc-generate

Unverified

Lightning Web Components with PICKLES methodology and 165-point scoring. Use this skill when the user creates or edits LWC components, builds wire service patterns, or writes Jest tests for LWC. TRIGGER when: user creates/edits LWC components, touches lwc/**/*.js, .html, .css, .js-meta.xml files, or asks about wire service, SLDS, or Jest LWC tests. DO NOT TRIGGER when: Apex classes (use platform-apex-generate), Aura components, or Visualforce.

FileKindSize
README.mdmarkdown4.1 KB
SKILL.mdskill md9.6 KB
assets/apex-controller/LwcController.clsother12.0 KB
assets/basic-component/basicComponent.cssother1.5 KB
assets/basic-component/basicComponent.htmlother4.5 KB
assets/basic-component/basicComponent.jsscript7.3 KB
assets/basic-component/basicComponent.js-meta.xmlconfig4.5 KB
assets/datatable-component/datatableComponent.htmlother4.1 KB
assets/datatable-component/datatableComponent.jsscript13.1 KB
assets/flow-screen-component/flowScreenComponent.cssother1.7 KB
assets/flow-screen-component/flowScreenComponent.htmlother7.1 KB
assets/flow-screen-component/flowScreenComponent.jsscript13.9 KB
assets/flow-screen-component/flowScreenComponent.js-meta.xmlconfig3.9 KB
assets/form-component/formComponent.htmlother6.4 KB
assets/form-component/formComponent.jsscript11.3 KB
assets/graphql-component/graphqlComponent.htmlother4.8 KB
assets/graphql-component/graphqlComponent.jsscript10.7 KB
assets/jest-test/componentName.test.js.exampleother15.6 KB
assets/message-channel/RecordSelected.messageChannel-meta.xmlconfig2.4 KB
assets/message-channel/lmsPublisher.jsscript3.8 KB
assets/message-channel/lmsSubscriber.jsscript7.0 KB
assets/modal-component/modalComponent.htmlother3.2 KB
assets/modal-component/modalComponent.jsscript5.5 KB
assets/record-picker/recordPicker.htmlother2.0 KB
assets/record-picker/recordPicker.jsscript5.4 KB
assets/state-store/store.jsscript9.1 KB
assets/typescript-component/typescriptComponent.cssother1.3 KB
assets/typescript-component/typescriptComponent.htmlother4.3 KB
assets/typescript-component/typescriptComponent.js-meta.xmlconfig2.4 KB
assets/typescript-component/typescriptComponent.test.ts.exampleother13.6 KB
assets/typescript-component/typescriptComponent.tsscript11.7 KB
assets/workspace-api/workspaceComponent.htmlother3.4 KB
assets/workspace-api/workspaceComponent.jsscript8.0 KB
references/accessibility-guide.mdmarkdown22.3 KB
references/advanced-features.mdmarkdown2.8 KB
references/async-notification-patterns.mdmarkdown19.7 KB
references/cli-commands.mdmarkdown12.6 KB
references/component-patterns.mdmarkdown44.5 KB
references/flow-integration-guide.mdmarkdown19.0 KB
references/jest-testing.mdmarkdown25.3 KB
references/lms-guide.mdmarkdown21.9 KB
references/lwc-best-practices.mdmarkdown36.3 KB
references/performance-guide.mdmarkdown20.3 KB
references/scoring-and-testing.mdmarkdown3.8 KB
references/slds-blueprints.jsonconfig781.3 KB
references/slds-design-guide.mdmarkdown10.7 KB
references/state-management.mdmarkdown19.9 KB
references/template-anti-patterns.mdmarkdown20.1 KB
references/triangle-pattern.mdmarkdown12.5 KB
scripts/local-dev-preview.shscript1.1 KB
scripts/lwc-lsp-validate.pyscript8.6 KB
scripts/post-tool-validate.pyscript14.7 KB
scripts/slds_data/deprecated_patterns.jsonconfig3.4 KB
scripts/slds_data/styling_hooks.jsonconfig2.9 KB
scripts/slds_data/valid_slds_classes.jsonconfig7.4 KB
scripts/slds_linter_wrapper.pyscript8.9 KB
scripts/slds_rules/__init__.pyscript593 B
scripts/template_validator.pyscript13.5 KB
scripts/validate_slds.pyscript26.5 KB

assets/datatable-component/datatableComponent.js

View on GitHub
/**
 * DATATABLE LWC COMPONENT TEMPLATE
 *
 * This template demonstrates lightning-datatable with:
 * - Column configuration
 * - Row selection (single/multi)
 * - Inline editing
 * - Sorting
 * - Infinite scrolling
 * - Row actions
 *
 * Replace: datatableComponent → yourComponentName
 */

import { LightningElement, api, wire, track } from 'lwc';
import { refreshApex } from '@salesforce/apex';
import { ShowToastEvent } from 'lightning/platformShowToastEvent';
import { NavigationMixin } from 'lightning/navigation';
import getRecords from '@salesforce/apex/DatatableController.getRecords';
import updateRecords from '@salesforce/apex/DatatableController.updateRecords';
import deleteRecords from '@salesforce/apex/DatatableController.deleteRecords';

// Row actions
const actions = [
    { label: 'View', name: 'view' },
    { label: 'Edit', name: 'edit' },
    { label: 'Delete', name: 'delete' }
];

// Column definitions
const COLUMNS = [
    {
        label: 'Account Name',
        fieldName: 'nameUrl',
        type: 'url',
        typeAttributes: {
            label: { fieldName: 'Name' },
            target: '_blank'
        },
        sortable: true
    },
    {
        label: 'Industry',
        fieldName: 'Industry',
        type: 'text',
        sortable: true,
        editable: true
    },
    {
        label: 'Annual Revenue',
        fieldName: 'AnnualRevenue',
        type: 'currency',
        typeAttributes: {
            currencyCode: 'USD',
            minimumFractionDigits: 0
        },
        sortable: true,
        editable: true,
        cellAttributes: { alignment: 'right' }
    },
    {
        label: 'Phone',
        fieldName: 'Phone',
        type: 'phone',
        editable: true
    },
    {
        label: 'Created Date',
        fieldName: 'CreatedDate',
        type: 'date',
        typeAttributes: {
            year: 'numeric',
            month: 'short',
            day: '2-digit',
            hour: '2-digit',
            minute: '2-digit'
        },
        sortable: true
    },
    {
        label: 'Active',
        fieldName: 'IsActive__c',
        type: 'boolean',
        editable: true
    },
    {
        type: 'action',
        typeAttributes: { rowActions: actions }
    }
];

export default class DatatableComponent extends NavigationMixin(LightningElement) {
    // ═══════════════════════════════════════════════════════════════════════
    // PUBLIC API
    // ═══════════════════════════════════════════════════════════════════════

    @api recordId;
    @api maxRows = 50;
    @api enableInfiniteScroll = false;
    @api showRowNumbers = false;

    // ═══════════════════════════════════════════════════════════════════════
    // PRIVATE PROPERTIES
    // ═══════════════════════════════════════════════════════════════════════

    columns = COLUMNS;
    @track data = [];
    error;
    isLoading = true;

    // Sorting
    sortBy;
    sortDirection = 'asc';

    // Selection
    selectedRows = [];
    draftValues = [];

    // Infinite scroll
    offset = 0;
    loadMoreStatus;
    totalRecords = 0;

    // Wire result for refresh
    wiredRecordsResult;

    // ═══════════════════════════════════════════════════════════════════════
    // WIRE SERVICE
    // ═══════════════════════════════════════════════════════════════════════

    @wire(getRecords, {
        parentId: '$recordId',
        limitSize: '$maxRows',
        offset: '$offset',
        sortBy: '$sortBy',
        sortDirection: '$sortDirection'
    })
    wiredRecords(result) {
        this.wiredRecordsResult = result;
        this.isLoading = false;

        const { data, error } = result;

        if (data) {
            // Add URL field for navigation
            this.data = data.records.map(record => ({
                ...record,
                nameUrl: `/${record.Id}`
            }));
            this.totalRecords = data.totalCount;
            this.error = undefined;
        } else if (error) {
            this.error = this.reduceErrors(error);
            this.data = [];
        }
    }

    // ═══════════════════════════════════════════════════════════════════════
    // GETTERS
    // ═══════════════════════════════════════════════════════════════════════

    get hasData() {
        return this.data && this.data.length > 0;
    }

    get hasSelection() {
        return this.selectedRows && this.selectedRows.length > 0;
    }

    get selectedCount() {
        return this.selectedRows.length;
    }

    get tableTitle() {
        return `Accounts (${this.totalRecords})`;
    }

    // ═══════════════════════════════════════════════════════════════════════
    // SORTING
    // ═══════════════════════════════════════════════════════════════════════

    handleSort(event) {
        this.sortBy = event.detail.fieldName;
        this.sortDirection = event.detail.sortDirection;
        this.isLoading = true;
        // Wire will automatically refetch with new sort params
    }

    // ═══════════════════════════════════════════════════════════════════════
    // SELECTION
    // ═══════════════════════════════════════════════════════════════════════

    handleRowSelection(event) {
        this.selectedRows = event.detail.selectedRows;

        // Dispatch event for parent
        this.dispatchEvent(new CustomEvent('selection', {
            detail: {
                selectedRows: this.selectedRows,
                selectedIds: this.selectedRows.map(row => row.Id)
            }
        }));
    }

    // ═══════════════════════════════════════════════════════════════════════
    // ROW ACTIONS
    // ═══════════════════════════════════════════════════════════════════════

    handleRowAction(event) {
        const actionName = event.detail.action.name;
        const row = event.detail.row;

        switch (actionName) {
            case 'view':
                this.navigateToView(row.Id);
                break;
            case 'edit':
                this.navigateToEdit(row.Id);
                break;
            case 'delete':
                this.handleDeleteRow(row);
                break;
            default:
                break;
        }
    }

    navigateToView(recordId) {
        this[NavigationMixin.Navigate]({
            type: 'standard__recordPage',
            attributes: {
                recordId: recordId,
                objectApiName: 'Account',
                actionName: 'view'
            }
        });
    }

    navigateToEdit(recordId) {
        this[NavigationMixin.Navigate]({
            type: 'standard__recordPage',
            attributes: {
                recordId: recordId,
                objectApiName: 'Account',
                actionName: 'edit'
            }
        });
    }

    async handleDeleteRow(row) {
        if (!confirm(`Delete ${row.Name}?`)) {
            return;
        }

        this.isLoading = true;
        try {
            await deleteRecords({ recordIds: [row.Id] });
            this.showToast('Success', 'Record deleted', 'success');
            await this.refresh();
        } catch (error) {
            this.showToast('Error', this.reduceErrors(error), 'error');
        } finally {
            this.isLoading = false;
        }
    }

    // ═══════════════════════════════════════════════════════════════════════
    // INLINE EDITING
    // ═══════════════════════════════════════════════════════════════════════

    handleCellChange(event) {
        this.draftValues = event.detail.draftValues;
    }

    async handleSave(event) {
        const updatedFields = event.detail.draftValues;
        this.isLoading = true;

        try {
            await updateRecords({ records: updatedFields });
            this.showToast('Success', 'Records updated', 'success');
            this.draftValues = [];
            await this.refresh();
        } catch (error) {
            this.showToast('Error', this.reduceErrors(error), 'error');
        } finally {
            this.isLoading = false;
        }
    }

    handleCancel() {
        this.draftValues = [];
    }

    // ═══════════════════════════════════════════════════════════════════════
    // INFINITE SCROLLING
    // ═══════════════════════════════════════════════════════════════════════

    loadMoreData(event) {
        if (!this.enableInfiniteScroll) return;

        const { target } = event;
        target.isLoading = true;

        if (this.data.length >= this.totalRecords) {
            target.enableInfiniteLoading = false;
            this.loadMoreStatus = 'All records loaded';
            target.isLoading = false;
            return;
        }

        this.offset = this.data.length;
        // Wire will load more data
    }

    // ═══════════════════════════════════════════════════════════════════════
    // BULK ACTIONS
    // ═══════════════════════════════════════════════════════════════════════

    async handleBulkDelete() {
        if (!this.hasSelection) return;

        const selectedIds = this.selectedRows.map(row => row.Id);

        if (!confirm(`Delete ${selectedIds.length} records?`)) {
            return;
        }

        this.isLoading = true;
        try {
            await deleteRecords({ recordIds: selectedIds });
            this.showToast('Success', `${selectedIds.length} records deleted`, 'success');
            this.selectedRows = [];
            await this.refresh();
        } catch (error) {
            this.showToast('Error', this.reduceErrors(error), 'error');
        } finally {
            this.isLoading = false;
        }
    }

    // ═══════════════════════════════════════════════════════════════════════
    // UTILITIES
    // ═══════════════════════════════════════════════════════════════════════

    async refresh() {
        this.isLoading = true;
        await refreshApex(this.wiredRecordsResult);
        this.isLoading = false;
    }

    handleRefresh() {
        this.refresh();
    }

    showToast(title, message, variant) {
        this.dispatchEvent(new ShowToastEvent({ title, message, variant }));
    }

    reduceErrors(errors) {
        if (!Array.isArray(errors)) errors = [errors];
        return errors
            .filter(e => !!e)
            .map(e => e.body?.message || e.message || JSON.stringify(e))
            .join(', ');
    }
}
finishing-a-development-branchobra/superpowersUse when implementation is complete, all tests pass, and you need to decide how to integrate the workStars: 322kUpdated Claude CodeCodexVerifiedInstall
systematic-debuggingobra/superpowersUse when encountering any bug, test failure, or unexpected behavior, before proposing fixesStars: 322kUpdated Claude CodeCodexVerifiedInstall
test-driven-developmentobra/superpowersUse when implementing any feature or bugfix, before writing implementation codeStars: 322kUpdated Claude CodeCodexVerifiedInstall
skill-creatoranthropics/skillsCreate new skills, modify and improve existing skills, and measure skill performance. Use when users want to create a skill from scratch, edit, or optimize an existing skill, run evals to test a skill, benchmark skill performance with variance analysis, or optimize a skill's description for better triggering accuracy.Stars: 198kUpdated Claude CodeCodexVerifiedInstall