• jaishri
  • NEWBIE
  • 110 Points
  • Member since 2021

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 39
    Questions
  • 41
    Replies
public class AccountTriggerHelper {
    public static void validateDeceasedAccounts(List<Account> newAccounts, Map<Id, Account> oldMap) {
        Set<Id> accIdSet = new Set<Id>();
        Map<Id, Case> casesMap = new Map<Id, Case>();

        for (Account acc : newAccounts) {
            Account oldAcc = oldMap.get(acc.Id);

            if (acc.Status__c == 'Deceased' && (
                    acc.DOB__c != oldAcc.DOB__c ||
                    acc.DOD__c != oldAcc.DOD__c ||
                    acc.Status__c != oldAcc.Status__c
                )) {
                if (acc.DOB__c == null || acc.DOD__c == null || acc.DOD__c <= acc.DOB__c) {
                    acc.addError('Please ensure that Date of Birth is populated, Date of Death is greater than Date of Birth, and Status is set to Deceased.');
                } else {
                    accIdSet.add(acc.Id);
                }
            }
        }

        if (!accIdSet.isEmpty()) {
            for (Case c : [SELECT Id, AccountId FROM Case WHERE AccountId IN :accIdSet AND Status != 'Closed']) {
                casesMap.put(c.AccountId, c);
            }
        }

        for (Account acc : newAccounts) {
            if (acc.Status__c == 'Deceased' && casesMap.containsKey(acc.Id)) {
                acc.addError('Please close all related cases before marking the status as Deceased.');
            }
        }
    }
}

 
trigger AccountTrigger on Account (before update) {
    for (Account acc : Trigger.new) {
        if (acc.Status__c == 'Deceased' && (acc.DOB__c == null || acc.DOD__c == null || acc.DOD__c <= acc.DOB__c)) {
            acc.addError('Please ensure that Date of Birth is populated, Date of Death is greater than Date of Birth, and Status is set to Deceased.');
        } else if (acc.Status__c == 'Deceased') {
            List<Case> relatedCases = [SELECT Id FROM Case WHERE AccountId = :acc.Id AND IsClosed = false];
            if (!relatedCases.isEmpty()) {
                acc.addError('Please close all related cases before marking the status as Deceased.');
            }
        }
    }
}

 
1) Create one screen flow where the 1st screen should have fields to create a Case.
2) Create another screen flow where the 1st screen should have fields to create an Opportunity.
3) Create a third flow "Summary flow" which shows the record details after successful creation in SF. The summary can have some of the field details, for Case Summary show case-related fields, for Opportunity summary show Opportunity fields.
<!--Use template if:true to display/hide popup based on isModalOpen value--> 
   <template if:true={isModalOpen}>
    <!-- Modal/Popup Box LWC starts here -->
    <section role="dialog" tabindex="-1" aria-labelledby="modal-heading-01" aria-modal="true" aria-describedby="modal-content-id-1" class="slds-modal slds-fade-in-open">
        <div class="slds-modal__container">
            <!-- Modal/Popup Box LWC header here -->
            <header class="slds-modal__header">
                <button class="slds-button slds-button_icon slds-modal__close slds-button_icon-inverse" title="Close" onclick={closeModal}>
                    <lightning-icon icon-name="utility:close"
                        alternative-text="close"
                        variant="inverse"
                        size="small" ></lightning-icon>
                    <span class="slds-assistive-text">Close</span>
                </button>
                <h2 id="modal-heading-01" class="slds-text-heading_medium slds-hyphenate">Guest User Registration</h2>
            </header>
            <div class="slds-modal__content slds-p-around_medium" id="modal-content-id-1">
                <form class="form-fields">
                    <div class="form-grid">
                        <div class="form-col-1">
                            <lightning-input type="text" label="First Name" placeholder="Enter your first name" onchange={handleFirstNameChange}></lightning-input>
                            <lightning-input type="text" label="Last Name" placeholder="Enter your last name" onchange={handleLastNameChange}></lightning-input>
                            <lightning-input type="email" label="Email" placeholder="Enter your email" onchange={handleEmailChange}></lightning-input>
                        </div>
                        <div class="form-col-2">
                            <lightning-input type="tel" label="Phone Number" placeholder="Enter your phone number" onchange={handlePhoneChange}></lightning-input>
                         <!--  <lightning-input type="text" label="Company Name" placeholder="Enter your company name" onchange={handleCompanyNameChange}></lightning-input> --> 
                            <lightning-input type="date" label="Birthdate" placeholder="Enter your birthdate" onchange={handleBirthdateChange}></lightning-input> 
                        </div>
                    </div>
                </form>
            </div>

                <footer class="slds-modal__footer">
                    <button class="slds-button slds-button_neutral" onclick={closeModal} title="Cancel">Cancel</button>
                    <button class="slds-button slds-button_brand" onclick={handleSave} title="Save">Save</button>
                </footer>
            </div>
        </section>
        <div class="slds-backdrop slds-backdrop_open"></div>
    </template>
 
import { LightningElement,track } from 'lwc';
import { createRecord } from 'lightning/uiRecordApi';
import { ShowToastEvent } from 'lightning/platformShowToastEvent';
import CONTACT_OBJECT from '@salesforce/schema/Contact';
import { NavigationMixin } from 'lightning/navigation';

export default class NewHomePage extends LightningElement {
    @track firstName = '';
    @track lastName = '';
    @track email = '';
    @track phone = '';
    @track companyname = '';
    @track birthdate = '';
    @track isModalOpen = false;

    handleFirstNameChange(event) {
        this.firstName = event.target.value;
    }

    handleLastNameChange(event) {
        this.lastName = event.target.value;
    }

    handleEmailChange(event) {
        this.email = event.target.value;
    }

    handlePhoneChange(event) {
        this.phone = event.target.value;
    }

    handleBirthdateChange(event) {
        this.birthdate = event.target.value;
    }

    handleSave() {
        const fields = {
            FirstName: this.firstName,
            LastName: this.lastName,
            Email: this.email,
            Birthdate : this.birthdate,
            Phone: this.phone
        };

        const recordInput = { apiName: CONTACT_OBJECT.objectApiName, fields };

        createRecord(recordInput)
            .then(() => {
                this.dispatchEvent(
                    new ShowToastEvent({
                        title: 'Success',
                        message: 'Contact created',
                        variant: 'success'
                    })
                );
                this.isModalOpen = false;
                this.firstName = '';
                this.lastName = '';
                this.email = '';
                this.birthdate = '';
                this.phone = '';

                this[NavigationMixin.Navigate]({
                    type: 'standard__webComponent',
                    attributes: {
                        webComponentName: 'c__questionFormPage',  // questionFormPage is lwc component
                    },
                    state: {
                        c__recordId: contact.id
                    }
                });
            })

            .catch(error => {
                this.dispatchEvent(
                    new ShowToastEvent({
                        title: 'Error creating contact',
                        message: error.body.message,
                        variant: 'error'
                    })
                );
            });

    }
    

    openModal() {
        this.isModalOpen = true;
    }
    closeModal() {
        this.isModalOpen = false;
    }
}

 
SELECT  PermissionSet.Profile.Name , PermissionSet.Name ,AssigneeId , Assignee.Name FROM PermissionSetAssignment GROUP BY  PermissionSet.Profile.Name ORDER BY PermissionSet.Profile.Name ASC
I want to create a report / excel  (security model ) to find out how many users have specific permission set .Is there is anyone to find 

I have two button save as draft and submit in that i gave the condition i can fill the form this week and previous and older week we can't submit or fill the form and i have disabled the button if it is save as draft in olderweek  below code
HTML

<lightning-button label="Save as Draft" variant="success" title="Save as Draft" onclick={handleDraft} class="slds-m-left_x-small" disabled={lockedToEdit}></lightning-button>
                        <lightning-button label="Submit" variant="brand" title="Submit" onclick={handleConfirmation} class="slds-m-left_x-small" disabled={lockedToEdit}></lightning-button>

JS

 submittedFlag = false;
 dayPassedFlag = false;

get lockedToEdit() {
        return this.submittedFlag || this.headView || this.dayPassedFlag;
    }
 //lasttwoweek condition
  if (last2Week.isoWeekday() == 7) {
            last2Week.subtract(1, 'weeks').startOf('isoWeek');
        } else {
            las2Week.subtract(1, 'weeks').startOf('isoWeek');
        }

 if (!this.headView && typeof this.existingFormcontinuation === 'undefined') {
            if (last2Week.isAfter(startDate)) {
                this.spinnerFlag = false;
                this.dispatchEvent(
                    new ShowToastEvent({
                        title: 'Error!!',
                        message: 'You can only fill the form for previous and current week!',
                        variant: 'error'
                    })
                );
                return this.changeDate();
            }
        } else if (!this.headView && typeof this.existingFormcontinuation === 'object') {
            if (last2Week.isAfter(startDate)) {
                this.dayPassedFlag = true;
            } else {
                this.dayPassedFlag = false;
            }
        }else {
            this.dayPassedFlag = false;
        }
now i want to enabled the button if anyone rejected the form in older weeks it is disabled by default because of the condition
List<CaseShare> csShareList = new List<CaseShare>();
for(case cs:trigger.new){
if(cs.Employee_Manager__c!=Null){
CaseShare csShare = new CaseShare();
// Give Read write access to that user for this particular case record.
csShare.CaseAccessLevel = 'Read';
// Assign case Id of case record.
csShare.CaseId = cs.id;
// Assign user id to grant read write access to this particular case record.
csShare.UserOrGroupId = cs.Employee_Manager__c;
csShare.RowCause='Manual';
csShareList.add( csShare );
}
}
insert csShareList;

 
Hi Evereyone, My requirment is i have to share a records of case created to particular field (lookup) in which multiple users are there .Every time user was changed for particular case.Can anyone suggest which approach i need to use or any solution. Manual sharing Apex sharing reason.

Thanks in advance
I'm getting issue in the below code can anyone help me where is wrong :- CaseAssignmentRuleTrigger: execution of BeforeInsert caused by: System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, CaseAssignmentRuleTrigger: maximum trigger depth exceeded Case trigger event BeforeInsert 
trigger CaseAssignmentRuleTrigger on Case (before insert,before update) {
    //Fetching the assignment rules on case
    AssignmentRule AR = new AssignmentRule();
    AR = [select id from AssignmentRule where SobjectType = 'Case' and Active = true limit 1];
    
    //Creating the DMLOptions for "Assign using active assignment rules" checkbox
    Database.DMLOptions dmlOpts = new Database.DMLOptions();
    dmlOpts.assignmentRuleHeader.assignmentRuleId= AR.id;
    
    Case newCase = new Case(Status = 'New') ;
    //Setting the DMLOption on Case instance
    newCase.setOptions(dmlOpts);
    insert newCase ;
}

 
I have requirement if checkbox(field level access ) is checked it will restrict the user and if checkbox is unchecked it will not restrict the user I created a method in apex and using a wire method to check the condition and if checkbox is checked it check the condition but it checkbox is unchecked it is showing error it is not checking /skiping the condition
Apex method

  @AuraEnabled(cacheable=true)
    public static User userData (String Ids){
        try {
            return [select id,Timesheet_Restriction_Bypass__c from user where Id =:Ids];
        } catch (Exception e) {
            throw new AuraHandledException(e.getMessage());
        }
    }
 
JS

import userData from '@salesforce/apex/FormController.userData';
import Id from '@salesforce/user/Id';
import Timesheet_Restriction_Bypass__c from '@salesforce/schema/User.Timesheet_Restriction_Bypass__c';
const fields=[Timesheet_Restriction_Bypass__c];

export default class Form extends LightningElement {
   userId = Id;
    userBypass;
    @track error;

    @wire(userData, { Ids: '0057h000004mseIAAQ' })
    userDetails({ error, data }) {
        console.log('~~data -- ', data);
        if (data) {
            console.log('d1');
            if (data.Timesheet_Restriction_Bypass__c ) {
                console.log('wwww'+data.Timesheet_Restriction_Bypass__c);
                this.userBypass = data.Timesheet_Restriction_Bypass__c;
            }
        }else if (error) {
            console.log('e2'+this.error);
            this.error = error;
            console.log('e3'+this.error);
        } 
    }
  if(this.userBypass == true)
        {
            console.log('inside worked'+this.userBypass);
        if (last2Week.isoWeekday() == 7) {
            last2Week.subtract(1, 'weeks').startOf('isoWeek');
        } else {
            last2Week.subtract(1, 'weeks').startOf('isoWeek');
        }
    }
}

Please anyone help me to find the issue.
Thanks in advance​​​​​​​
Hi, Anyone Help me In datepicker I'm selecting a previous week or current week It will show and we can choose but my requirment is if i want to select the past weeks it will show the toast mess you can't select the past week i don't want to disable the dates in datepicker if anyone know help me
trigger AccountTrigger on Account (before update) {
    for (Account acc : Trigger.new) {
        if (acc.Status__c == 'Deceased' && (acc.DOB__c == null || acc.DOD__c == null || acc.DOD__c <= acc.DOB__c)) {
            acc.addError('Please ensure that Date of Birth is populated, Date of Death is greater than Date of Birth, and Status is set to Deceased.');
        } else if (acc.Status__c == 'Deceased') {
            List<Case> relatedCases = [SELECT Id FROM Case WHERE AccountId = :acc.Id AND IsClosed = false];
            if (!relatedCases.isEmpty()) {
                acc.addError('Please close all related cases before marking the status as Deceased.');
            }
        }
    }
}

 
List<CaseShare> csShareList = new List<CaseShare>();
for(case cs:trigger.new){
if(cs.Employee_Manager__c!=Null){
CaseShare csShare = new CaseShare();
// Give Read write access to that user for this particular case record.
csShare.CaseAccessLevel = 'Read';
// Assign case Id of case record.
csShare.CaseId = cs.id;
// Assign user id to grant read write access to this particular case record.
csShare.UserOrGroupId = cs.Employee_Manager__c;
csShare.RowCause='Manual';
csShareList.add( csShare );
}
}
insert csShareList;

 
Hi Evereyone, My requirment is i have to share a records of case created to particular field (lookup) in which multiple users are there .Every time user was changed for particular case.Can anyone suggest which approach i need to use or any solution. Manual sharing Apex sharing reason.

Thanks in advance
I'm getting issue in the below code can anyone help me where is wrong :- CaseAssignmentRuleTrigger: execution of BeforeInsert caused by: System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, CaseAssignmentRuleTrigger: maximum trigger depth exceeded Case trigger event BeforeInsert 
trigger CaseAssignmentRuleTrigger on Case (before insert,before update) {
    //Fetching the assignment rules on case
    AssignmentRule AR = new AssignmentRule();
    AR = [select id from AssignmentRule where SobjectType = 'Case' and Active = true limit 1];
    
    //Creating the DMLOptions for "Assign using active assignment rules" checkbox
    Database.DMLOptions dmlOpts = new Database.DMLOptions();
    dmlOpts.assignmentRuleHeader.assignmentRuleId= AR.id;
    
    Case newCase = new Case(Status = 'New') ;
    //Setting the DMLOption on Case instance
    newCase.setOptions(dmlOpts);
    insert newCase ;
}

 
accountForm.html

<template>
    <div class="slds-grid slds-gutters">
        <div class="slds-col">
            <span>
                <lightning-input type="Currency" label="AnnualRevenue Start" value={revenueStart} name="AVStart"
                    onchange={handleChange} placeholder="Enter Value"></lightning-input>
            </span>
        </div>
        <div class="slds-col">
            <span>
                <lightning-input type="Currency" label="AnnualRevenue End" value={revenueEnd} name="AVEnd"
                    onchange={handleChange} placeholder="Enter Value"> </lightning-input>
            </span>
        </div>
        <div class="slds-col">
            <span>
                <template if:true={typeValues.data}>
                    <lightning-combobox name="Type" label="Type" value={value} options={typeValues.data.values}
                        onchange={handleChange} placeholder="Select Type">
                    </lightning-combobox>
                </template>
            </span>
        </div>
        <div class="slds-col">
            <span>
                <template if:true={ratingValues.data}>
                    <lightning-combobox name="Rating" label="Rating" value={value} options={ratingValues.data.values}
                        onchange={handleChange} placeholder="Select Rating">
                    </lightning-combobox>
                </template>
            </span>
        </div>
        <div class="slds-col">
            <span>
                <template if:true={industryValues.data}>
                    <lightning-combobox name="Industry" label="Industry" value={value}
                        options={industryValues.data.values} onchange={handleChange} placeholder="Select Industry">
                    </lightning-combobox>
                </template>
            </span>
        </div>
    </div>

    <lightning-button type="submit" variant="brand" label="Show Accounts" onclick={handleClick}></lightning-button>

    <template if:true={showSearchtable}>
        <lightning-datatable key-field="Id" data={accounts} columns={columns} onsave={handleSave}
            draft-values={draftValues} sorted-by={sortBy} sorted-direction={sortDirection} onsort={doSorting}
            hide-checkbox-column="true"></lightning-datatable>
    </template>
    
    <template if:true={showSearchComponent}>
        <p>No data to display</p>
    </template>

    <template if:true={loading}>
        <div class="slds-spinner_container">
            <lightning-spinner alternative-text="Loading" variant="brand" size="medium">
            </lightning-spinner>
        </div>
    </template>
    <div class="slds-m-around_medium">
        <p class="slds-m-vertical_medium content">
            Displaying {startingRecord} to {endingRecord} of {totalRecountCount} records.
            Page {page} of {totalPage}. </p>
        <c-paginator onprevious={previousHandler} onnext={nextHandler}></c-paginator>
    </div>
</template>
 
accountForm.js

import { LightningElement, wire, track, api } from 'lwc';

import { getPicklistValues } from 'lightning/uiObjectInfoApi';
import Type from '@salesforce/schema/Account.Type';
import Rating from '@salesforce/schema/Account.Rating';
import AnnualRevenue from '@salesforce/schema/Account.AnnualRevenue';
import ChangeRating__c from '@salesforce/schema/Account.ChangeRating__c';

import { getObjectInfo } from 'lightning/uiObjectInfoApi';
import ACCOUNT_OBJECT from '@salesforce/schema/Account';
import Industry from '@salesforce/schema/Account.Industry';

import getAccountList from '@salesforce/apex/AccountForm.getAccountList';



import { updateRecord } from 'lightning/uiRecordApi';
import { ShowToastEvent } from 'lightning/platformShowToastEvent';


const columns = [
  { label: 'Account Name', fieldName: 'AccName', type: 'url', sortable: "true", typeAttributes: { label: { fieldName: 'Name' } } },
  { label: 'AnnualRevenue', fieldName: 'AnnualRevenue', type: 'currency', editable: true, sortable: "true" },

  { label: 'Industry', fieldName: 'Industry', editable: true, sortable: "true" },
  { label: 'Type', fieldName: 'Type', editable: true, sortable: "true" },
  { label: 'Rating', fieldName: 'Rating', type: 'picklist', editable: true, sortable: "true" },
  { label: 'Website', fieldName: 'Website', type: 'url', editable: true, sortable: "true" },
  { label: 'ChangeRating', fieldName: 'ChangeRating__c', type: 'number', editable: true, sortable: "true" }
];

let i = 0;
export default class AccountForm extends LightningElement {

  @track page = 1;
  @track items = [];
  @track columns;
  @track startingRecord = 1;
  @track endingRecord = 0;
  @track pageSize = 10;
  @track totalRecountCount = 0;
  @track totalPage = 0;

  @track accounts = [];
  @track showSearchComponent = false;
  @track showSearchtable;
  @track revenueStart;
  @track revenueEnd;
  @track loading = false;
  @track sortBy;
  @track sortDirection;

  @api recordId;
  columns = columns;
  draftValues = [];

  @wire(getObjectInfo, { objectApiName: ACCOUNT_OBJECT })
  accountInfo;
  nameVal;
  typeVal;
  industryVal;

  @wire(getPicklistValues, {
    recordTypeId: '$accountInfo.data.defaultRecordTypeId',
    fieldApiName: Type

  })
  typeValues;

  @wire(getPicklistValues, { recordTypeId: '$accountInfo.data.defaultRecordTypeId', fieldApiName: Rating })
  ratingValues;

  @wire(getPicklistValues, { recordTypeId: '$accountInfo.data.defaultRecordTypeId', fieldApiName: Industry })
  industryValues;


  handleChange(event) {
    var fieldname = event.target.label;
    if (fieldname == 'Rating') {
      this.nameVal = event.target.value;
    }
    else if (fieldname == 'Type') {
      this.typeVal = event.target.value;
    } else if (fieldname == 'Industry') {
      this.industryVal = event.target.value;
    }
    else if (fieldname == 'AnnualRevenue Start') {
      this.revenueStart = event.target.value;
    }
    else if (fieldname == 'AnnualRevenue End') {
      this.revenueEnd = event.target.value;
    }
  }

  handleClick() {
    this.showSearchComponent = true;
    this.loading = true;
    console.log('AnnualRevenueStart --> ', this.revenueStart);
    console.log('Anuual end --> ', this.revenueEnd);
    if (this.revenueEnd != null && this.revenueEnd != '' && this.revenueStart != null && this.revenueStart != '' && this.revenueEnd < this.revenueStart) {
      console.log('this.revenueEnd' + this.revenueEnd);
      this.loading = false;
      console.log('Alert message');
      const toastEvt = new ShowToastEvent({
        title: 'Error',
        message: 'AnnualRevenueEnd should not be lesser than AnnualRevenueStart',
        variant: 'error',

      });
      this.dispatchEvent(toastEvt);
    }
    else {
      getAccountList({ type: this.typeVal, rating: this.nameVal, industry: this.industryVal, AnnualRevenueStart: this.revenueStart, AnnualRevenueEnd: this.revenueEnd })
        .then(results => {
          if (results != null) {
            let tempAccList = [];
            results.forEach((result) => {
              let tempAccRec = Object.assign({}, result);
              tempAccRec.AccName = '/' + tempAccRec.Id;
              tempAccList.push(tempAccRec);
              this.showSearchComponent = false;
              this.showSearchtable = true;
              this.accounts = tempAccList;
            });
            if (accounts) {
              this.items = accounts;
              this.totalRecountCount = accounts.length;
              this.totalPage = Math.ceil(this.totalRecountCount / this.pageSize);
              this.accounts = this.items.slice(0, this.pageSize);
              this.endingRecord = this.pageSize;
              this.columns = columns;

              this.error = undefined;
            } else if (error) {
              this.error = error;
              this.accounts = undefined;
            }
          }
          else {
            this.showSearchtable = false;
            this.showSearchComponent = true;
          }
          this.loading = false;
        })
        .catch(error => {
          console.log('error' + error);
          this.loading = false;
        })
    }
  }

  handleSave(event) {
    const recordInputs = event.detail.draftValues.slice().map(draft => {
      const fields = Object.assign({}, draft);
      return { fields };
    });

    const promises = recordInputs.map(recordInput => updateRecord(recordInput));
    Promise.all(promises).then(accounts => {
      this.dispatchEvent(
        new ShowToastEvent({
          title: 'Success',
          message: 'Accounts updated',
          variant: 'success'
        })
      );
      // Clear all draft values
      this.draftValues = [];

      // Display fresh data in the 
      this.handleClick();

    }).catch(error => {
      // Handle error
    });
  }

  doSorting(event) {
    this.sortBy = event.detail.fieldName;
    this.sortDirection = event.detail.sortDirection;
    this.sortData(this.sortBy, this.sortDirection);
  }

  sortData(fieldname, direction) {
    let parseData = JSON.parse(JSON.stringify(this.accounts));

    let keyValue = (a) => {
      return a[fieldname];
    };

    let isReverse = direction === 'asc' ? 1 : -1;

    parseData.sort((x, y) => {
      x = keyValue(x) ? keyValue(x) : '';
      y = keyValue(y) ? keyValue(y) : '';

      return isReverse * ((x > y) - (y > x));
    });
    this.accounts = parseData;
  }

  previousHandler() {
    if (this.page > 1) {
      this.page = this.page - 1;
      this.displayRecordPerPage(this.page);
    }
  }
  nextHandler() {
    if ((this.page < this.totalPage) && this.page !== this.totalPage) {
      this.page = this.page + 1;
      this.displayRecordPerPage(this.page);
    }
  }
  displayRecordPerPage(page) {
    this.startingRecord = ((page - 1) * this.pageSize);
    this.endingRecord = (this.pageSize * page);
    this.endingRecord = (this.endingRecord > this.totalRecountCount)
      ? this.totalRecountCount : this.endingRecord;
    this.accounts = this.items.slice(this.startingRecord, this.endingRecord);
    this.startingRecord = this.startingRecord + 1;
  }
}
 
AccountForm.cls

public with sharing class AccountForm {
    @AuraEnabled
    public static List<Account>  getAccountList(String type,String rating,String industry,String AnnualRevenueStart,String AnnualRevenueEnd){
        System.debug('AnnualRevenueStart='+AnnualRevenueStart);
        System.debug('AnnualRevenueEnd='+AnnualRevenueEnd);
        String accQuery = 'SELECT Id,Name,Website,Type,Rating,AnnualRevenue,Industry,ChangeRating__c FROM Account';                     
        String whereClause  = '';
        String Query1;
        Integer arStart;
        if(String.isNotEmpty(AnnualRevenueStart)){
            arStart = Integer.valueOf(AnnualRevenueStart);
        }
        Integer arEnd;
        if(String.isNotEmpty(AnnualRevenueEnd)){
            arEnd = Integer.valueOf(AnnualRevenueEnd);
        }
        if(arStart!=Null){
            whereClause=whereClause+' where AnnualRevenue>=:arStart';
        }
        if(arEnd!=Null){
            if(String.isEmpty(whereClause)){
                whereClause=whereClause+' WHERE AnnualRevenue<=:arEnd';
            }
            else 
            {
                whereClause=whereClause+' AND AnnualRevenue<=:arEnd';
            }
        }
        if(String.isNotEmpty(type)){
            if(String.isEmpty(whereClause)){
                whereClause =whereClause +  ' WHERE Type = :type';
            }else{
                whereClause =whereClause + ' AND Type = :type';
            }
            
        }
        if(String.isNotEmpty(rating)){
            if(String.isEmpty(whereClause)){
                whereClause =whereClause +  ' WHERE Rating = :rating';
            }else{
                whereClause =whereClause + ' AND Rating = :rating';
            }
        } 
        if(String.isNotEmpty(industry)){
            if(String.isEmpty(whereClause)){
                whereClause =whereClause +  ' WHERE Industry = :industry';
            }else{
                whereClause =whereClause + ' AND Industry = :industry';
            }
            
        } 
        String finalquery = accQuery+whereClause;
        System.debug('finalquery='+finalquery);
        
        List<Account> acclist=Database.query(finalquery);
        if(acclist.size()>0){
            return acclist;
        }
        else {
            return null;
            
        }
    }  
}
 
paginator.html

<template>
    <lightning-layout>
        <lightning-layout-item>
            <lightning-button label="Previous" icon-name="utility:chevronleft" onclick={previousHandler}></lightning-button>
        </lightning-layout-item>
        <lightning-layout-item flexibility="grow"></lightning-layout-item>
        <lightning-layout-item>
            <lightning-button label="Next" icon-name="utility:chevronright" icon-position="right" onclick={nextHandler}></lightning-button>
        </lightning-layout-item>
    </lightning-layout>
</template>
 
paginator.js

import { LightningElement} from 'lwc';

export default class Paginator extends LightningElement {
    previousHandler() {
        this.dispatchEvent(new CustomEvent('previous'));
    }

    nextHandler() {
        this.dispatchEvent(new CustomEvent('next'));
    }
}

 
<template>
    <div class="slds-p-around_medium lgc-bg">
        <lightning-input type="Currency" label="AnnualRevenue Start" value={revenueStart} name="AVStart"
            onchange={handleChange}></lightning-input>
    </div>

    <div class="slds-p-around_medium lgc-bg">
        <lightning-input type="Currency" label="AnnualRevenue End" value={revenueEnd} name="AVEnd"
            onchange={handleChange}> </lightning-input>

    </div>

    <div class="slds-p-around_medium lgc-bg">
        <template if:true={typeValues.data}>
            <lightning-combobox name="Type" label="Type" value={value} options={typeValues.data.values}
                onchange={handleChange}>
            </lightning-combobox>
        </template>
    </div>

    <div class="slds-p-around_medium lgc-bg">
        <template if:true={ratingValues.data}>
            <lightning-combobox name="Rating" label="Rating" value={value} options={ratingValues.data.values}
                onchange={handleChange}>
            </lightning-combobox>
        </template>
    </div>

    <div class="slds-p-around_medium lgc-bg">
        <template if:true={industryValues.data}>
            <lightning-combobox name="Industry" label="Industry" value={value} options={industryValues.data.values}
                onchange={handleChange}>
            </lightning-combobox>
        </template>
    </div>

    <lightning-button type="submit" variant="brand" label="Show Accounts" onclick={handleClick}></lightning-button>
    
    <template if:true={showSearchComponent}>
        <lightning-datatable key-field="Id" data={accounts} columns={columns} onsave={handleSave}
            draft-values={draftValues} hide-checkbox-column="true"></lightning-datatable>
    </template>

    <template if:false={accounts}>
        <p>No data to display</p>
    </template>

    <template if:true={loading}>
        <div class="slds-spinner_container">
            <lightning-spinner alternative-text="Loading" variant="brand" size="medium">
            </lightning-spinner>
        </div>
    </template>
</template>
 
import { LightningElement, wire, track, api } from 'lwc';

import { getPicklistValues } from 'lightning/uiObjectInfoApi';
import Type from '@salesforce/schema/Account.Type';
import Rating from '@salesforce/schema/Account.Rating';
import AnnualRevenue from '@salesforce/schema/Account.AnnualRevenue';

// import ChangeRating__c from '@salesforce/schema/Account.ChangeRating__c';

import { getObjectInfo } from 'lightning/uiObjectInfoApi';
import ACCOUNT_OBJECT from '@salesforce/schema/Account';
import Industry from '@salesforce/schema/Account.Industry';

import getAccountList from '@salesforce/apex/AccountForm.getAccountList';

//import getAccounts from '@salesforce/apex/AccountForm.getAccounts';
import { updateRecord } from 'lightning/uiRecordApi';
import { ShowToastEvent } from 'lightning/platformShowToastEvent';
import { refreshApex } from '@salesforce/apex';

const columns = [
  { label: 'Account Name', fieldName: 'AccName', type: 'url', typeAttributes: { label: { fieldName: 'Name' } } },
  { label: 'AnnualRevenue', fieldName: 'AnnualRevenue', type: 'currency', editable: true },
  { label: 'Industry', fieldName: 'Industry' },
  { label: 'Type', fieldName: 'Type', editable: true },
  { label: 'Rating', fieldName: 'Rating', type: 'picklist', editable: true },
  { label: 'Website', fieldName: 'Website', type: 'url', editable: true },
  { label: 'ChangeRating', fieldName: 'ChangeRating__c', type: 'number', editable: true }
];

export default class AccountForm extends LightningElement {

  @track accounts;
  @track showSearchComponent = false;
  @track loading = false;
  @track revenueStart;
  @track revenueEnd;
  @api recordId;
  columns = columns;
  draftValues = [];
  accounts ;

  error;
  empty = false;


  @wire(getObjectInfo, { objectApiName: ACCOUNT_OBJECT })
  accountInfo;
  nameVal;
  typeVal;
  industryVal;


  @wire(getPicklistValues, { recordTypeId: '$accountInfo.data.defaultRecordTypeId', fieldApiName: Type })
  typeValues;

  @wire(getPicklistValues, { recordTypeId: '$accountInfo.data.defaultRecordTypeId', fieldApiName: Rating })
  ratingValues;

  @wire(getPicklistValues, { recordTypeId: '$accountInfo.data.defaultRecordTypeId', fieldApiName: Industry })
  industryValues;


  handleChange(event) {
    var fieldname = event.target.label;
    if (fieldname == 'Rating') {
      this.nameVal = event.target.value;
    } else if (fieldname == 'Type') {
      this.typeVal = event.target.value;
    } else if (fieldname == 'Industry') {
      this.industryVal = event.target.value;
    } else if (fieldname == 'AnnualRevenue Start') {
      this.revenueStart = event.target.value;
    } else if (fieldname == 'AnnualRevenue End') {
      this.revenueEnd = event.target.value;
    }
  }

  handleClick() {
    // console.log('buttom clicked');
    this.showSearchComponent = true;
    this.loading = true;
    //console.log('type--> '+this.typeVal+' rating--> '+this.nameVal+' industry--> '+this.industryVal);
    getAccountList({ type: this.typeVal, rating: this.nameVal, industry: this.industryVal, AnnualRevenueStart: this.revenueStart, AnnualRevenueEnd: this.revenueEnd })
      .then(results => {
        // console.log('account result--> '+JSON.stringify(result))
        let tempAccList = [];

        results.forEach((result) => {
          let tempAccRec = Object.assign({}, result);
          tempAccRec.AccName = '/' + tempAccRec.Id;
          tempAccList.push(tempAccRec);

        });
            this.accounts = tempAccList
        //  this.accounts=result;
            this.loading = false;
      })
      .catch(error => {
        console.log('error' + error);
        this.loading = false;
      })


  }


  handleSave(event) {
    const recordInputs = event.detail.draftValues.slice().map(draft => {
      const fields = Object.assign({}, draft);
      return { fields };
    });

    const promises = recordInputs.map(recordInput => updateRecord(recordInput));
    Promise.all(promises).then(accounts => {
      this.dispatchEvent(
        new ShowToastEvent({
          title: 'Success',
          message: 'Accounts updated',
          variant: 'success'
        })

      );
      // Clear all draft values
      this.draftValues = [];

      // Display fresh data in the datatable
      return refreshApex(this.accounts);
    }).catch(error => {
      // Handle error
    });
  }

public with sharing class AccountForm {
    @AuraEnabled
    public static List<Account>  getAccountList(String type,String rating,String industry,Integer AnnualRevenueStart,Integer AnnualRevenueEnd){
        String accQuery = 'SELECT Id,Name,Type,Rating,AnnualRevenue FROM Account';                     
        String whereClause  = '';
        
     /*   if(AnnualRevenueStart>=30000){
            whereClause =whereClause +' where AnnualRevenue>=30000';
        }
       if(AnnualRevenueEnd<=100000){
            whereClause =whereClause +' AND AnnualRevenue<=100000';
            
        }*/

        if(AnnualRevenueStart!=Null){
            whereClause=whereClause+' where AnnualRevenue>=:AnnualRevenueStart';
        }
        if(AnnualRevenueEnd!=Null){
            if(String.isEmpty(whereClause)){
            whereClause=whereClause+' WHERE AnnualRevenue<=:AnnualRevenueEnd';
        }
        else 
            {
                whereClause=whereClause+' AND AnnualRevenue<=:AnnualRevenueEnd';
            }
        }

        if(String.isNotEmpty(type)){
            if(String.isEmpty(whereClause)){
                whereClause =whereClause +  ' WHERE Type = :type';
            }else{
                whereClause =whereClause + ' AND Type = :type';
            }
            
        }
        if(String.isNotEmpty(rating)){
            if(String.isEmpty(whereClause)){
                whereClause =whereClause +  ' WHERE Rating = :rating';
            }else{
                whereClause =whereClause + ' AND Rating = :rating';
            }
        } 
        if(String.isNotEmpty(industry)){
            if(String.isEmpty(whereClause)){
                whereClause =whereClause +  ' WHERE Industry = :industry';
            }else{
                whereClause =whereClause + ' AND Industry = :industry';
            }
            
        } 
        String finalquery = accQuery+whereClause;
        System.debug('finalquery='+finalquery);
        
        List<Account> acclist=Database.query(finalquery);
        
        return acclist;
        
    }
}
I have build lwc component which show datatable when i give the input in field but when i change field data in row it is also save in datatable but the data is showing after refresh the whole page after saving the field it is not updating in UI Page.....can anyone help me

 
Test Class 

@isTest
    public static void testmethod3(){
        contact con = new contact();
        con.LastName = 'Test contact';
        con.Email = 'sample@sample.com';
        insert con;
        List<Case> caseList = new List<Case>();
        for(Integer i=1; i<=200 ; i++){
            Case cs = new Case();
            cs.Status = 'New';
            cs.Origin = 'Phone';
            cs.ContactId =con.Id;
            caseList.add(cs);
        }
        
          Test.startTest();
          insert caseList;
          Test.stopTest();
    
}

 
Trigger

trigger CaseTrigger on Case (after insert,after delete) {
    system.debug('trigger value--> '+Trigger.isDelete+'and--> '+Trigger.IsAfter);
    CaseTriggerHandler CaseHandler = new CaseTriggerHandler();
    if(Trigger.isInsert&&Trigger.IsAfter){
        system.debug('inside insert trigger');
        CaseHandler.AfterInsert(Trigger.new);
    }
    if(Trigger.isDelete&&Trigger.IsAfter){
        system.debug('inside isDelete trigger');
        CaseHandler.AfterDelete(Trigger.old);
    }
 
Handler class 
  
   public class CaseTriggerHandler {
    public void AfterInsert(List<Case> case1){
        system.debug('inside CaseTriggerHandler insert trigger '+case1);
        List<Messaging.SingleEmailMessage> emails = new List<Messaging.SingleEmailMessage>();
        
        TestEmailCase__mdt testEmail = [select id, Label,NamespacePrefix,To_Address__c from TestEmailCase__mdt];
        system.debug('test case list -->'+testEmail); 
        for(Case ca:case1){
            system.debug('test email start -->'+testEmail.To_Address__c); 
            Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
            List<String> eid = new List<String>();
            
            eid.add(testEmail.To_Address__c);
            email.setToAddresses(eid);
            email.setSubject('case create');
            email.setPlainTextBody('case created');
            emails.add(email);
            system.debug('test email end -->'); 
        }
        Messaging.sendEmail(emails);
    }
    public void AfterDelete(List<Case> case1){
        List<Messaging.SingleEmailMessage> emails = new List<Messaging.SingleEmailMessage>();
        
        TestEmailCase__mdt testEmail = [select id, Label,NamespacePrefix,To_Address__c from TestEmailCase__mdt];
        system.debug(testEmail);
        
        for(Case ca:case1){
            Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
            List<String> eid = new List<String>();
            
            eid.add(testEmail.To_Address__c);
            email.setToAddresses(eid);
            email.setSubject('case deleted');
            email.setPlainTextBody('case deleted');
            emails.add(email);
        }
        Messaging.sendEmail(emails);
    }
}
 
Test Class
    
  @isTest
public class CaseTriggerHandler_Test_class{

     @isTest static void setup() {
        // Create common test accounts
        List<Case> testCase = new List<Case>();
        for(Integer i=0;i<1;i++) {
            Case cas = new Case();  
            cas.Origin='Email';
            cas.Subject='Test Case';
            cas.Status = 'Closed case';
            cas.To_Address__c = 'sample@sample.com';
            testCase.add(cas);
        }
        insert testCase;  
        
        Delete testCase;
        
    }