0

I'm using apex:pageMessage to display warning message on record page. I'm using a visualforce page and embedding it into the page layout and display the error message based on certain record values, as below:

<apex:pageMessage summary="This is a warning message!" 
                  severity="warning" 
                  strength="3"
                  rendered="{!IF(sField1 =='xxx' && sField2 !='xxx', true, false)}" />
</apex:page>

How can I implement the same functionality with lwc?

0

You have a few options on LWC like building your own component to handle error messages. There is the fireToast that perhaps it is the easiest one. On your LWC HTML import this:

import { getDetailsFromError, fireToast } from 'c/lwcutils';

After that you can use you fireToast in your functions like this:

fireToast(this, 'error', 'Error', 'message');
// or this for success 
fireToast(this, 'success', 'Success!', 'message');

This will fire a toast. If you want to have an error that stays on the page and be able to show that error on a particular place on the page, I will suggest to build a component for that.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.