forcedotcom/sf-skills / plugins/builder/experience-lwc/skills/experience-lwc-generate
experience-lwc-generate
UnverifiedLightning 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.
assets/message-channel/lmsPublisher.js
View on GitHub/**
* LIGHTNING MESSAGE SERVICE - PUBLISHER TEMPLATE
*
* This component demonstrates publishing messages via LMS.
* Use LMS when components need to communicate but:
* - Don't have a parent-child relationship
* - Are in different parts of the page
* - Need to communicate between LWC, Aura, and Visualforce
*
* Replace: lmsPublisher → yourComponentName
*/
import { LightningElement, wire } from 'lwc';
import { publish, MessageContext } from 'lightning/messageService';
import RECORD_SELECTED_CHANNEL from '@salesforce/messageChannel/RecordSelected__c';
export default class LmsPublisher extends LightningElement {
// ═══════════════════════════════════════════════════════════════════════
// MESSAGE CONTEXT
// ═══════════════════════════════════════════════════════════════════════
/**
* MessageContext provides the scope for publishing/subscribing.
* Wire it to get the current context automatically.
*/
@wire(MessageContext)
messageContext;
// ═══════════════════════════════════════════════════════════════════════
// PUBLISH METHODS
// ═══════════════════════════════════════════════════════════════════════
/**
* Publish a simple message with record selection
*/
handleRecordSelect(event) {
const recordId = event.target.dataset.id;
const recordName = event.target.dataset.name;
// Create message payload
const payload = {
recordId: recordId,
recordName: recordName,
objectApiName: 'Account',
sourceComponent: 'lmsPublisher',
timestamp: new Date().toISOString()
};
// Publish to the message channel
publish(this.messageContext, RECORD_SELECTED_CHANNEL, payload);
console.log('Published message:', payload);
}
/**
* Publish with complex payload (JSON string for nested data)
*/
publishWithComplexPayload(recordData) {
const payload = {
recordId: recordData.Id,
recordName: recordData.Name,
objectApiName: 'Account',
sourceComponent: 'lmsPublisher',
timestamp: new Date().toISOString(),
payload: JSON.stringify({
additionalField1: recordData.field1,
additionalField2: recordData.field2,
nestedObject: {
key1: 'value1',
key2: 'value2'
}
})
};
publish(this.messageContext, RECORD_SELECTED_CHANNEL, payload);
}
/**
* Publish from imperative action (e.g., after Apex call)
*/
async handleSaveAndPublish() {
try {
// Perform some action
const result = await this.saveRecord();
// Publish result to other components
publish(this.messageContext, RECORD_SELECTED_CHANNEL, {
recordId: result.Id,
recordName: result.Name,
objectApiName: 'Account',
sourceComponent: 'lmsPublisher',
timestamp: new Date().toISOString()
});
} catch (error) {
console.error('Save failed:', error);
}
}
// Placeholder for actual save logic
async saveRecord() {
return { Id: '001xx000000000', Name: 'Test Account' };
}
}
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| finishing-a-development-branchobra/superpowersUse when implementation is complete, all tests pass, and you need to decide how to integrate the work | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| systematic-debuggingobra/superpowersUse when encountering any bug, test failure, or unexpected behavior, before proposing fixes | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| test-driven-developmentobra/superpowersUse when implementing any feature or bugfix, before writing implementation code | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| 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: 198k | Updated | Claude CodeCodex | Verified | Install |