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.

1import { LightningElement, wire } from "lwc";
2
3import rebuildHeroku from "@salesforce/apex/CmsControlPanelController.rebuildHeroku";
4
5import refreshMarketingCloud from "@salesforce/apex/CmsControlPanelController.refreshMarketingCloud";
6
7export default class CmsControlPanel extends LightningElement {
8  waitingOnHeroku = false;
9  waitingOnMarketingCloud = false;
10
11  herokuResponse;
12  mcResponse;
13
14  async handleHerokuRebuildClick() {
15    this.waitingOnHeroku = true;
16
17    this.herokuResponse = await rebuildHeroku();
18
19    this.waitingOnHeroku = false;
20  }
21
22  async handleMarketingCloudRebuildClick() {
23    this.waitingOnMarketingCloud = true;
24
25    this.mcResponse = await refreshMarketingCloud();
26
27    this.waitingOnMarketingCloud = false;
28  }
29
30  get mcStatus() {
31    let currentStatus = "";
32
33    if (this.waitingOnMarketingCloud) {
34      currentStatus = "Marketing Cloud is currently being refreshed";
35    } else {
36      currentStatus = "no actions in progress";
37    }
38
39    return currentStatus;
40  }
41
42  get herokuStatus() {
43    let currentStatus = "";
44
45    if (this.waitingOnHeroku) {
46      currentStatus = "Heroku is currently being refreshed";
47    } else {
48      currentStatus = "no actions in progress";
49    }
50
51    return currentStatus;
52  }
53}

See Also