Development questions
What is Lightning Message Service (LMS) and how do you use it to communicate between components?
DevelopmentMedium
LMS lets components on the same Lightning page communicate regardless of DOM hierarchy, and works across LWC, Aura and Visualforce.
Steps:
- Create a Lightning Message Channel metadata file (
MyChannel.messageChannel-meta.xml) defining fields. - Publisher imports the channel and
publish:
javascript
import { publish, MessageContext } from 'lightning/messageService';
import CHANNEL from '@salesforce/messageChannel/MyChannel__c';
@wire(MessageContext) messageContext;
publish(this.messageContext, CHANNEL, { recordId: this.id });
- Subscriber uses
subscribeinconnectedCallbackandunsubscribeindisconnectedCallback.
It replaces the old pub-sub pattern and is the supported way to talk between unrelated components.
lwclmsmessaging
More Development questions
- What is an Apex Trigger in Salesforce and when should you use it over Flows?
- What is the difference between before triggers and after triggers?
- Explain all Trigger context variables (isInsert, isUpdate, isDelete, isUndelete, isBefore, isAfter, isExecuting, size, operationType).
- What is the difference between Trigger.new and Trigger.old?
- In which trigger events are Trigger.new and Trigger.newMap available?
- In which trigger events are Trigger.old and Trigger.oldMap available?