Rest API Callout from LWC Salesforce- using row action in Lightning data table

Поділитися
Вставка
  • Опубліковано 16 лип 2023
  • This video is the demo of making callout from lightning data table of salesforce LWC where callout will happen after clicking the row action button and then toast message will render.
    #salesforce #lwc #restapi #callouts #salesforcetrailhead #salesforceinterviewquestions #usedcase #tutorial #tutorials #salesforceapex

КОМЕНТАРІ • 6

  • @SohelMd123
    @SohelMd123 7 місяців тому +2

    Great session. Thank you.

  • @forcesales
    @forcesales  9 місяців тому

    In case of any query you can reach out to me at linkedin.com/in/gagan-anand-328b8ba2

  • @santanuroy571
    @santanuroy571 8 місяців тому

    Can you share the code please if possible?

    • @forcesales
      @forcesales  8 місяців тому

      give me your email id , I will share the code

    • @forcesales
      @forcesales  8 місяців тому

      import { LightningElement,wire } from 'lwc';
      import retrieveAccounts from '@salesforce/apex/DataController.retrieveAccounts';
      import { ShowToastEvent } from 'lightning/platformShowToastEvent';
      import { NavigationMixin } from 'lightning/navigation';
      import postToSAP from '@salesforce/apex/DataController.callSAPSystem';
      const actions = [
      { label: 'View', name: 'view' , initialWidth:300},
      { label: 'Edit', name: 'edit' , initialWidth:300},
      ];

      const columns = [
      { label: 'Id', fieldName: 'Id',initialWidth:100 },
      { label: 'Name', fieldName: 'Name', sortable: true ,initialWidth:150 },
      { label: 'Type', fieldName: 'Type', sortable: true , initialWidth:150
      },
      {
      label: 'Outside Action',
      type: 'button',
      initialWidth:150,
      typeAttributes: {
      label: 'Send to SAP',
      name: 'sendtosap',
      disabled: {fieldName : 'iscloneDisabled'},
      value: 'viewBtn' }
      },
      { label: 'Action',
      type: 'action',
      initialWidth:300,
      typeAttributes: { rowActions: actions },
      },
      ];
      export default class Datatablepostaction extends NavigationMixin(LightningElement) {
      columns = columns;
      items;
      error;

      @wire(retrieveAccounts)
      wiredAccounts({ error, data }) {
      if (data) {
      this.items = data;
      this.columns = columns;
      this.error = undefined;
      } else if (error) {
      this.error = error;
      this.items = undefined;
      this.showToast(this.error, 'Error', 'Error'); //show toast for error
      }
      }

      handleRowAction(event) {
      console.log('testinsidehandler');
      const actionName = event.detail.action.name;
      const row = event.detail.row;
      console.log('actionaname'+actionName);
      console.log('row'+row.Id);
      console.log('row'+this.row);
      switch ( actionName ) {
      case 'view':
      this[NavigationMixin.Navigate]({
      type: 'standard__recordPage',
      attributes: {
      objectApiName: 'Account',
      recordId: row.Id,
      actionName: 'view'
      }
      });
      break;
      case 'edit':
      this[NavigationMixin.Navigate]({
      type: 'standard__recordPage',
      attributes: {
      recordId: row.Id,
      objectApiName: 'Account',
      actionName: 'edit'
      }
      });
      break;
      }
      if(actionName=='sendtosap'){
      console.log('inside sendtosap');
      postToSAP({ AccountId: row.Id })
      .then(result => {
      this.error = undefined;
      })
      .catch(error => {
      this.error = error;
      })
      this.showToast();
      }
      }

      showToast() {
      const event = new ShowToastEvent({
      title: 'Callout succesfull !!',
      message: 'Data has been sent to the SAP',
      variant: 'success',
      mode: 'dismissable'
      });
      this.dispatchEvent(event);
      }

      }

    • @ramyaaranjith3961
      @ramyaaranjith3961 2 місяці тому

      Can you share code pls in git