createDataset

Creates a CRM Analytics dataset.

Syntax 

1import { createDataset } from 'lightning/analyticsWaveApi';
2createDataset( dataset : DatasetInput ): Promise<Dataset>

CRM Analytics API Resource 

1POST /wave/datasets

createDataset uses this CRM Analytics API resource.

Parameters 

Parameter NameTypeDescriptionRequired?
datasetObjectThe dataset to create. Use a Dataset Input resource.Yes

Returns 

A Promise object that resolves with the Dataset response.

Usage 

Use createDataset to create a CRM Analytics dataset. For example, create a dataset from the Accounts object.

This example adds a create button to a page. The page must contain form elements for the information required to create the dataset, like the dataset type. Creating a dataset displays a toast message using the lightning/platformShowToastEvent module.

1import { LightningElement, api } from "lwc";
2import { createDataset } from "lightning/analyticsWaveApi";
3import { ShowToastEvent } from "lightning/platformShowToastEvent";
4
5export default class CreateDataset extends LightningElement {
6  dataset = {
7    type: "Default",
8  };
9
10  create(event) {
11    createDataset({ dataset: this.dataset })
12      .then(() => {
13        this.dispatchEvent(
14          new ShowToastEvent({
15            title: "Success",
16            message: "Dataset Created",
17            variant: "success",
18          }),
19        );
20      })
21      .catch((error) => {
22        this.dispatchEvent(
23          new ShowToastEvent({
24            title: "Error creating dataset",
25            message: error.body.message,
26            variant: "error",
27          }),
28        );
29      });
30  }
31}

This button calls the createDataset() method.

1<template>
2  <lightning-button
3    label="Create"
4    icon-name="utility:play"
5    icon-position="right"
6    onclick={create}
7  ></lightning-button>
8</template>