• anantha Lakshmi kuppala
  • NEWBIE
  • 0 Points
  • Member since 2022

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 0
    Replies
import { api, LightningElement } from 'lwc';
import contactFirstName from '@salesforce/schema/Contact.FirstName';
import contactLastName from '@salesforce/schema/Contact.LastName';
import contactEmail from '@salesforce/schema/Contact.Email';
import contactPhone from '@salesforce/schema/Contact.Phone';
import contactAccount from '@salesforce/schema/Contact.AccountId';
import {ShowToastEvent} from 'lightning/platformShowToastEvent';
 
export default class updateRecordLwc extends LightningElement {
    @api ContactObjectApiName='Contact';
    @api recordId;
    ContactFieldList = [contactFirstName,contactLastName,contactEmail,contactPhone,contactAccount];
 
    contactHandleUpdate(event){
        const evt = new ShowToastEvent({
            title:'Record Updated',
            message:'Contact record: ' + event.detail.fields.LastName.value + 'is successfully updated',
            variant:'success',
          })
          this.dispatchEvent(evt);
    }
}

Html
<template>
    <lightning-card title="LWC Example 2">
        <br/><br/>
        <h2 class="slds-text-color--error">How to Edit/Update record without apex class by help of the lightning data service in LWC</h2>
 
        <lightning-record-form object-api-name={ContactObjectApiName} fields={ContactFieldList} record-id={recordId} onsuccess={contactHandleUpdate}></lightning-record-form>
 
<br/><br/>
</lightning-card>
</template>
html code:
<template>
        <!--fetching accounts and its related contacts-->
        <b>Accounts Table:</b>
        <table>
                <tr>
                        <th>Account Id</th>
                        <th>Account Name</th>
                        <th>Fetch Contacts</th>
                        <th>Contacts</th>
                </tr>
                <template iterator:acct={accounts.data}>
                        <tr key={acct.value.Id} style="border-bottom: 1px solid #ccc;">
                                <td a-name={acct.value.Name}>{acct.value.Id}</td>
                                <td a-name={acct.value.Name}>{acct.value.Name}</td>
                                <td><c-accounts-deletion key={acct.value.Id} account-id={acct.value.Id}></c-accounts-deletion></td>
                        </tr>
                </template>
        </table>
        <!--fetching Accounts and deleting on click-->
        <b>Accounts Table:</b>
        <table>
                <tr>
                        <th>Account Id</th>
                        <th>Account Name</th>
                        <th>Delete ?</th>
                </tr>
                <template iterator:acct={accounts.data}>
                        <tr key={acct.value.Id} style="border-bottom: 1px solid #ccc;">
                                <td a-name={acct.value.Name}>{acct.value.Id}</td>
                                <td a-name={acct.value.Name}>{acct.value.Name}</td>
                                <td><button key={acct.value.Id} a-name={acct.value.Name} data-id={acct.value.Id} onclick={deleteAccount}>Delete</button></td>
                        </tr>
                </template>
        </table>
</template>
javs script code .js:
import { LightningElement, wire } from 'lwc';
import getAccounts from '@salesforce/apex/Dataloader.getAccounts';
import deleteAccount from '@salesforce/apex/Dataloader.deleteAccount';
export default class accountsdeletion extends LightningElement {
        @wire(getAccounts) accounts;
        deleteAccount(event){
                const acctId=event.target.getAttribute('data-id');
                const accName=event.target.getAttribute('a-name');
                deleteAccount({id: acctId}).then(()=>{
                        alert("Account:"+accName+" delete, Please refresh page to check");
                }).catch(error=>{console.log(error)});
        }
}

apex class:
public class Dataloader {
@AuraEnabled(cacheable=true)
    public static void deleteAccount(string id){
        DELETE[SELECT Id, Name FROM Account where Id=:id];
    }
}
public class dfsmlwccontroller {
    @AuraEnabled(cacheable=true)
    public static List<Contact> getLwcContacts(string accountId){
        return [SELECT Id, Name FROM Contact WHERE accountId=:accountId];
    }
}
while running statement dfsmlwccontroller.getLwcContacts(); using debug open excute anonymos window getting

Line: 1, Column: 19
Method does not exist or incorrect signature: void getLwcContacts() from the type dfsmlwccontroller