How To display LWC Toast component on Salesforce Case only when the Roll up Record Count Field on the Case object is not null

To show the LWC Toast component only when the Roll up Record Count Field on the Case object is not null, you can use a conditional rendering in the template of the LWC component.

Here's an example of how you can do this:

<template>
  <!-- Display the toast component only if the rollUpRecordCount field is not null -->
  <template if:true={rollUpRecordCount}>
    <lightning-toast message="Toast message" variant="info"></lightning-toast>
  </template>
</template>

<script>
import { LightningElement, track } from 'lwc';

export default class MyLWCComponent extends LightningElement {
  @track rollUpRecordCount;

  connectedCallback() {
    // Assume that this.rollUpRecordCount is set to the value of the Roll up Record Count Field on the Case object
    if (this.rollUpRecordCount) {
      this.template.querySelector('lightning-toast').show();
    }
  }
}
</script>

In the template, the lightning-toast element is wrapped in a template element with a if:true directive. This directive allows you to conditionally render the element based on the value of rollUpRecordCount. If the value is truthy, the lightning-toast element will be rendered. Otherwise, it will not be rendered.

In the connectedCallback method, we check if rollUpRecordCount is truthy. If it is, we call the show method on the lightning-toast element to display the toast notification.

I hope this helps! Let me know if you have any questions.

Quit your soul sucking dead-end job and live the life you’ve always dreamed of. Whether it’s traveling to exotic locations around the world…Buy anything you want without having to check out the price tags…
And never having to worry about bills.

Click here to access this “Wealth DNA” report to awaken your dormant ability to attract wealth and abundance.

Leave a Reply

Your email address will not be published. Required fields are marked *