JavaScript Lightning Web Component Sample

This sample shows the JavaScript portion of a Lightning web component for a content sync panel. When a user clicks a button on the content sync panel, the event triggers the JavaScript functions in this file.

The function calls the matching Apex method created in Step 2: Write Apex to Send an HTTP Call to the Connected App.

import { LightningElement, wire } from "lwc";

import rebuildHeroku from "@salesforce/apex/CmsControlPanelController.rebuildHeroku";

import refreshMarketingCloud from "@salesforce/apex/CmsControlPanelController.refreshMarketingCloud";

export default class CmsControlPanel extends LightningElement {
  waitingOnHeroku = false;
  waitingOnMarketingCloud = false;

  herokuResponse;
  mcResponse;

  async handleHerokuRebuildClick() {
    this.waitingOnHeroku = true;

    this.herokuResponse = await rebuildHeroku();

    this.waitingOnHeroku = false;
  }

  async handleMarketingCloudRebuildClick() {
    this.waitingOnMarketingCloud = true;

    this.mcResponse = await refreshMarketingCloud();

    this.waitingOnMarketingCloud = false;
  }

  get mcStatus() {
    let currentStatus = "";

    if (this.waitingOnMarketingCloud) {
      currentStatus = "Marketing Cloud is currently being refreshed";
    } else {
      currentStatus = "no actions in progress";
    }

    return currentStatus;
  }

  get herokuStatus() {
    let currentStatus = "";

    if (this.waitingOnHeroku) {
      currentStatus = "Heroku is currently being refreshed";
    } else {
      currentStatus = "no actions in progress";
    }

    return currentStatus;
  }
}

See Also