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/apex-controller/LwcController.cls

View on GitHub
/**
 * APEX CONTROLLER TEMPLATE FOR LWC
 *
 * This template demonstrates @AuraEnabled methods for LWC with:
 * - Cacheable methods for wire service
 * - Non-cacheable methods for data mutations
 * - Proper error handling
 * - Security enforcement
 * - Bulk-safe patterns
 *
 * Replace: LwcController → YourControllerName
 */
public with sharing class LwcController {

    // ═══════════════════════════════════════════════════════════════════════
    // CACHEABLE METHODS (For @wire service)
    // ═══════════════════════════════════════════════════════════════════════

    /**
     * Get records for display in LWC
     * Use with @wire decorator for automatic caching and refresh
     *
     * @param parentId - Parent record ID (optional filter)
     * @param searchTerm - Search filter (optional)
     * @param limitSize - Max records to return
     * @return List of Account records
     */
    @AuraEnabled(cacheable=true)
    public static List<Account> getAccounts(Id parentId, String searchTerm, Integer limitSize) {
        try {
            Integer recordLimit = limitSize != null ? limitSize : 50;
            String searchKey = String.isNotBlank(searchTerm)
                ? '%' + String.escapeSingleQuotes(searchTerm) + '%'
                : '%';

            return [
                SELECT Id, Name, Industry, AnnualRevenue, Phone, CreatedDate
                FROM Account
                WHERE Name LIKE :searchKey
                WITH SECURITY_ENFORCED
                ORDER BY Name
                LIMIT :recordLimit
            ];
        } catch (Exception e) {
            throw new AuraHandledException(e.getMessage());
        }
    }

    /**
     * Get single record by ID
     */
    @AuraEnabled(cacheable=true)
    public static Account getAccountById(Id accountId) {
        try {
            List<Account> accounts = [
                SELECT Id, Name, Industry, AnnualRevenue, Phone, BillingAddress,
                       (SELECT Id, FirstName, LastName, Email FROM Contacts LIMIT 5)
                FROM Account
                WHERE Id = :accountId
                WITH SECURITY_ENFORCED
                LIMIT 1
            ];

            if (accounts.isEmpty()) {
                throw new AuraHandledException('Account not found');
            }

            return accounts[0];
        } catch (Exception e) {
            throw new AuraHandledException(e.getMessage());
        }
    }

    /**
     * Get picklist values for a field
     */
    @AuraEnabled(cacheable=true)
    public static List<PicklistOption> getIndustryOptions() {
        List<PicklistOption> options = new List<PicklistOption>();

        Schema.DescribeFieldResult fieldResult = Account.Industry.getDescribe();
        List<Schema.PicklistEntry> entries = fieldResult.getPicklistValues();

        for (Schema.PicklistEntry entry : entries) {
            if (entry.isActive()) {
                options.add(new PicklistOption(entry.getLabel(), entry.getValue()));
            }
        }

        return options;
    }

    // ═══════════════════════════════════════════════════════════════════════
    // NON-CACHEABLE METHODS (For data mutations)
    // ═══════════════════════════════════════════════════════════════════════

    /**
     * Create a new account
     *
     * @param accountData - JSON string of account fields
     * @return Created Account with Id
     */
    @AuraEnabled
    public static Account createAccount(String accountData) {
        try {
            // Parse JSON to Map
            Map<String, Object> fieldMap = (Map<String, Object>) JSON.deserializeUntyped(accountData);

            // Create Account record
            Account newAccount = new Account();
            newAccount.Name = (String) fieldMap.get('Name');
            newAccount.Industry = (String) fieldMap.get('Industry');
            newAccount.Phone = (String) fieldMap.get('Phone');

            // Validate required fields
            if (String.isBlank(newAccount.Name)) {
                throw new AuraHandledException('Account name is required');
            }

            // Insert with security check
            SObjectAccessDecision decision = Security.stripInaccessible(
                AccessType.CREATABLE,
                new List<Account>{ newAccount }
            );
            insert decision.getRecords();

            return (Account) decision.getRecords()[0];
        } catch (DmlException e) {
            throw new AuraHandledException(e.getDmlMessage(0));
        } catch (Exception e) {
            throw new AuraHandledException(e.getMessage());
        }
    }

    /**
     * Update an existing account
     *
     * @param accountId - Record ID to update
     * @param accountData - JSON string of fields to update
     * @return Updated Account
     */
    @AuraEnabled
    public static Account updateAccount(Id accountId, String accountData) {
        try {
            // Verify record exists and user has access
            List<Account> existing = [
                SELECT Id FROM Account
                WHERE Id = :accountId
                WITH SECURITY_ENFORCED
                LIMIT 1
            ];

            if (existing.isEmpty()) {
                throw new AuraHandledException('Account not found or access denied');
            }

            // Parse and apply updates
            Map<String, Object> fieldMap = (Map<String, Object>) JSON.deserializeUntyped(accountData);

            Account accountToUpdate = new Account(Id = accountId);

            if (fieldMap.containsKey('Name')) {
                accountToUpdate.Name = (String) fieldMap.get('Name');
            }
            if (fieldMap.containsKey('Industry')) {
                accountToUpdate.Industry = (String) fieldMap.get('Industry');
            }
            if (fieldMap.containsKey('Phone')) {
                accountToUpdate.Phone = (String) fieldMap.get('Phone');
            }

            // Update with security check
            SObjectAccessDecision decision = Security.stripInaccessible(
                AccessType.UPDATABLE,
                new List<Account>{ accountToUpdate }
            );
            update decision.getRecords();

            // Return refreshed record
            return getAccountById(accountId);
        } catch (DmlException e) {
            throw new AuraHandledException(e.getDmlMessage(0));
        } catch (Exception e) {
            throw new AuraHandledException(e.getMessage());
        }
    }

    /**
     * Delete records
     *
     * @param recordIds - List of record IDs to delete
     */
    @AuraEnabled
    public static void deleteAccounts(List<Id> recordIds) {
        try {
            if (recordIds == null || recordIds.isEmpty()) {
                throw new AuraHandledException('No records specified for deletion');
            }

            // Query records to verify access
            List<Account> accountsToDelete = [
                SELECT Id FROM Account
                WHERE Id IN :recordIds
                WITH SECURITY_ENFORCED
            ];

            if (accountsToDelete.size() != recordIds.size()) {
                throw new AuraHandledException('Some records not found or access denied');
            }

            delete accountsToDelete;
        } catch (DmlException e) {
            throw new AuraHandledException(e.getDmlMessage(0));
        } catch (Exception e) {
            throw new AuraHandledException(e.getMessage());
        }
    }

    /**
     * Bulk update records (for datatable inline editing)
     *
     * @param records - List of records with Id and fields to update
     */
    @AuraEnabled
    public static void updateRecords(List<Account> records) {
        try {
            if (records == null || records.isEmpty()) {
                return;
            }

            // Security check
            SObjectAccessDecision decision = Security.stripInaccessible(
                AccessType.UPDATABLE,
                records
            );

            update decision.getRecords();
        } catch (DmlException e) {
            throw new AuraHandledException(e.getDmlMessage(0));
        } catch (Exception e) {
            throw new AuraHandledException(e.getMessage());
        }
    }

    // ═══════════════════════════════════════════════════════════════════════
    // PAGINATED QUERY (For infinite scrolling)
    // ═══════════════════════════════════════════════════════════════════════

    /**
     * Get paginated records for infinite scrolling
     *
     * @param limitSize - Records per page
     * @param offset - Starting position
     * @param sortBy - Field to sort by
     * @param sortDirection - ASC or DESC
     * @return PagedResult with records and total count
     */
    @AuraEnabled(cacheable=true)
    public static PagedResult getPagedAccounts(
        Integer limitSize,
        Integer offset,
        String sortBy,
        String sortDirection
    ) {
        try {
            Integer recordLimit = limitSize != null ? limitSize : 50;
            Integer recordOffset = offset != null ? offset : 0;
            String sortField = String.isNotBlank(sortBy) ? sortBy : 'Name';
            String sortDir = sortDirection == 'desc' ? 'DESC' : 'ASC';

            // Whitelist allowed sort fields to prevent SOQL injection
            Set<String> allowedSortFields = new Set<String>{
                'Name', 'Industry', 'AnnualRevenue', 'CreatedDate', 'Phone'
            };

            if (!allowedSortFields.contains(sortField)) {
                sortField = 'Name';
            }

            // Build dynamic query
            String query = 'SELECT Id, Name, Industry, AnnualRevenue, Phone, CreatedDate ' +
                          'FROM Account ' +
                          'WITH SECURITY_ENFORCED ' +
                          'ORDER BY ' + sortField + ' ' + sortDir + ' NULLS LAST ' +
                          'LIMIT :recordLimit OFFSET :recordOffset';

            List<Account> records = Database.query(query);

            // Get total count
            Integer totalCount = [SELECT COUNT() FROM Account WITH SECURITY_ENFORCED];

            return new PagedResult(records, totalCount);
        } catch (Exception e) {
            throw new AuraHandledException(e.getMessage());
        }
    }

    // ═══════════════════════════════════════════════════════════════════════
    // WRAPPER CLASSES
    // ═══════════════════════════════════════════════════════════════════════

    /**
     * Wrapper for picklist options
     */
    public class PicklistOption {
        @AuraEnabled public String label;
        @AuraEnabled public String value;

        public PicklistOption(String label, String value) {
            this.label = label;
            this.value = value;
        }
    }

    /**
     * Wrapper for paginated results
     */
    public class PagedResult {
        @AuraEnabled public List<Account> records;
        @AuraEnabled public Integer totalCount;

        public PagedResult(List<Account> records, Integer totalCount) {
            this.records = records;
            this.totalCount = totalCount;
        }
    }
}
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