Table in vf page

<!-- expenseTrackerLWC.html -->
<template>
  <div class="container">
    <!-- Filter Section -->
    <div class="filter-section">
      <div class="slds-grid slds-gutters">
        <!-- Picklist for object selection -->
        <div class="slds-col">
          <lightning-combobox
            label="Select Object"
            value={selectedObject}
            options={objectOptions}
            onchange={handleObjectChange}
          ></lightning-combobox>
        </div>
        
        <!-- Search input -->
        <div class="slds-col">
          <lightning-input
            type="text"
            label="Search"
            value={searchKey}
            onchange={handleSearchKeyChange}
          ></lightning-input>
        </div>
      </div>
    </div>
    
    <!-- Table Section -->
    <div class="table-section">
      <table class="slds-table slds-table_bordered slds-table_cell-buffer slds-table_col-bordered">
        <thead>
          <tr>
            <th>Expense Code</th>
            <th>Expense Type</th>
            <th>Name</th>
            <th>Link</th>
          </tr>
        </thead>
        <tbody>
          <template for:each={data} for:item="item" for:index="index">
            <tr key={item.id}>
              <td>{item.expenseCode}</td>
              <td>{item.expenseType}</td>
              <td>{item.name}</td>
              <td>
                <a href={item.link} target="_blank" rel="noopener noreferrer">
                  View Record
                </a>
              </td>
            </tr>
          </template>
        </tbody>
      </table>
    </div>

    <!-- Pagination Section -->
    <div class="pagination-section">
      <lightning-layout>
        <lightning-layout-item size="6">
          <!-- Previous button -->
          <lightning-button-icon
            icon-name="utility:left"
            variant="bare"
            onclick={handlePrevious}
            disabled={currentPage === 1}
          ></lightning-button-icon>
        </lightning-layout-item>
        <lightning-layout-item size="6">
          <!-- Next button -->
          <lightning-button-icon
            icon-name="utility:right"
            variant="bare"
            onclick={handleNext}
            disabled={currentPage === totalPages}
          ></lightning-button-icon>
        </lightning-layout-item>
      </lightning-layout>

      <!-- Picklist for records per page -->
      <lightning-combobox
        label="Records per Page"
        value={pageSize}
        options={pageSizeOptions}
        onchange={handlePageSizeChange}
      ></lightning-combobox>
    </div>
  </div>
</template>

// expenseTrackerLWC.js
import { LightningElement, track, wire } from ‘lwc’;
import getExpenses from ‘@salesforce/apex/ExpenseTrackerController.getExpenses’;

export default class ExpenseTrackerLWC extends LightningElement {
@track data = []; // Data to display in the table
@track currentPage = 1;
@track pageSize = 10; // Number of records to display per page
@track totalRecords = 0;
@track selectedObject = ‘Account’; // Default selected object
@track searchKey = ”;

// Define options for the object picklist
objectOptions = [
{ label: ‘Account’, value: ‘Account’ },
{ label: ‘Opportunity’, value: ‘Opportunity’ },
{ label: ‘HR_Team__c’, value: ‘HR_Team__c’ }
];

// Define options for the records per page picklist
pageSizeOptions = [
{ label: ’10’, value: 10 },
{ label: ’25’, value: 25 },
{ label: ’50’, value: 50 }
];

// Fetch data from Apex on component initialization
@wire(getExpenses, {
pageNumber: ‘$currentPage’,
pageSize: ‘$pageSize’,
selectedObject: ‘$selectedObject’,
searchKey: ‘$searchKey’
})
wiredExpenses({ error, data }) {
if (data) {
this.data = data.records;
this.totalRecords = data.totalRecords;
} else if (error) {
// Handle error
}
}

// Handle object selection change
handleObjectChange(event) {
this.selectedObject = event.detail.value;
this.currentPage = 1; // Reset to the first page when changing objects
}

// Handle search input change
handleSearchKeyChange(event) {
this.searchKey = event.detail.value;
this.currentPage = 1; // Reset to the first page when searching
}

// Handle pagination – Next button
handleNext() {
if (this.currentPage < this.totalPages) {
this.currentPage++;
}
}

// Handle pagination – Previous button
handlePrevious() {
if (this.currentPage > 1) {
this.currentPage–;
}
}

// Handle records per page picklist change
handlePageSizeChange(event) {
this.pageSize = event.detail.value;
this.currentPage = 1; // Reset to the first page when changing page size
}

// Calculate total pages for pagination
get totalPages() {
return Math.ceil(this.totalRecords / this.pageSize);
}
}

public with sharing class ExpenseTrackerController { @AuraEnabled(cacheable=true) public static ExpenseDataWrapper getExpenses(Integer pageNumber, Integer pageSize, String selectedObject, String searchKey) { // Define a wrapper class to hold the results ExpenseDataWrapper result = new ExpenseDataWrapper(); // Determine the object to query based on selectedObject String objectToQuery = ‘Account’; if (selectedObject == ‘Opportunity’) { objectToQuery = ‘Opportunity’; } else if (selectedObject == ‘HR_Team__c’) { objectToQuery = ‘HR_Team__c’; } // Build the SOQL query String query = ‘SELECT Id, Expense_Code__c, Name, Link__c FROM ‘ + objectToQuery; // Apply search filter if searchKey is provided if (!String.isEmpty(searchKey)) { query += ‘ WHERE (Expense_Code__c LIKE :searchKey OR Name LIKE :searchKey)’; } // Execute the query with pagination result.records = Database.query(query + ‘ LIMIT :pageSize OFFSET :offset’); // Get the total count of records (without pagination) Integer totalCount = [SELECT COUNT() FROM ‘ + objectToQuery + ‘ WHERE (Expense_Code__c LIKE :searchKey OR Name LIKE :searchKey)’]; result.totalRecords = totalCount; return result; } // Wrapper class to hold query results and total record count public class ExpenseDataWrapper { @AuraEnabled public List<Expense__c> records { get; set; } @AuraEnabled public Integer totalRecords { get; set; } }}

Salesforce : Process Builder will be deprecated

There is big announcement coming up and that is process builder will be deprecated in 2023.
Yes our lovely process builder.
So Salesforce Flow is the future and its high time we need to shift our focus and start learning flows.

I have already added videos and created a playlist which is enough for you to get started on flows. So
Do checkout the channel and subscribe to it for more knowledge on salesforce.

Flow tutorials Link : https://youtube.com/playlist?list=PLzFf5oGFkpPsMXYaNhHvCYtPG-2lPjoMo

Salesforce Interview Questions: Important Interview Questions on Lightning Web Components

Q 1: What is Lightning Web Component ?

https://knowledgepredator.com/2020/06…

Q 2: What was the need Lightning Web Component ?

https://knowledgepredator.com/2020/06…

Q 3: What difference you feel while working with Lightning Web Component as compared to Aura Component? https://knowledgepredator.com/2020/06…

Q 4: What are benefits of LWC?

https://knowledgepredator.com/2020/06…

Q 5: Can we use LWC inside Aura and Vice-Versa?

https://knowledgepredator.com/2020/06…

Q 6: Can we communicate between aura and LWC Components?

https://knowledgepredator.com/2020/06…

Q 7: What are life Cycle Hooks in LWC?

https://knowledgepredator.com/2020/06…

Q 8: What are decorators in LWC?

https://knowledgepredator.com/2020/06…

Q 9:What is use of @api and @track Decorators?

https://knowledgepredator.com/2020/06…

Q 10: Explain @wire decorator?

https://knowledgepredator.com/2020/06…

Q 11: Is it mandatory to write cacheable = true for aura enabled method bind with @wire decorator?

https://knowledgepredator.com/2020/06…

Q 12: What is imperative call to Server in LWC?

https://knowledgepredator.com/2020/06…

Q 13: Can we write cacheable = true on server side method called using imperative way in LWC? https://knowledgepredator.com/2020/06…

Q 14: What is one-way binding and two way binding. Which one is there in LWC?

https://www.youtube.com/watch?v=ZEMpM…

Q 15: Can we make the Wire method to refresh forcefully and bring fresh data from server?

Yes we can do that. Use refreshApex method to acvhieve this.

https://developer.salesforce.com/docs/component-library/documentation/en/lwc/lwc.apex_result_caching

Q 16: What are custom Events in LWC?

https://knowledgepredator.com/2020/06…

Q 17: How can we communicate from parent component to child component in LWC ? https://knowledgepredator.com/2020/06…

Q 18: How can we communicate from child component to parent component in LWC ? https://knowledgepredator.com/2020/06…

Q 19: How can we pass data from parent component to child component in LWC ?

https://knowledgepredator.com/2020/06…

Q 20: Can we call child Component method from parent in LWC?

https://knowledgepredator.com/2020/06…

Q 21: How can we communicate between unrelated components in LWC?

https://knowledgepredator.com/2020/06…

Q 22: What is pub sub in LWC?

https://knowledgepredator.com/2020/06…

Q 23: What is Lightning Message Service in LWC?

https://developer.salesforce.com/docs/component-library/bundle/lightning-message-service/documentation

Q 24: Explain the Folder Structure of LWC Component?

https://knowledgepredator.com/2020/06…

Q 25: Can we include more than one JavaScript file in LWC Component?

https://knowledgepredator.com/2020/06…

Q 26: Can we include more than one HTML file in LWC Component?

https://knowledgepredator.com/2020/06…

Q 27: How can we include LWC Component inside Home Page, Record Page or App Page in Salesforce? https://knowledgepredator.com/2020/06…

Q 28: How can we add Spinners in LWC?

https://knowledgepredator.com/2020/06…

Q 29: How can we add Toast Messages in LWC?

https://knowledgepredator.com/2020/06…

Q 30: How to include LWC Component inside VF Page?

We can include our lwc component inside aura component. Then use lightning out feature to include that aura lightning component inside VF page

Q 31: How to communicate between Aura and LWC component?

We can achieve this using custom events.

Q 32: What is Validity Attribute in LWC?

https://www.youtube.com/watch?v=n3zrp…

Q 33: How to set custom validity in LWC?

https://www.youtube.com/watch?v=n3zrp…

Please check below video if you want to know the detailed explaination of all these questions:

Lightning Flows in Salesforce: How to Assign records to Queue using Flows

In this topic, we will discuss, how we can assign records to Queues with the help of lightning flows in salesforce.

Problem Statement: When a case record is created with subject containing ‘predator’, assign the record to a Queue – ‘CasePredatorQueue’.

Please check below video for more detailed explaination :

If you have any questions related to this topic, please add them in comments section of the video.

Lightning Flows in Salesforce: Sending Email Alerts Using Salesforce Lightning Flows

In this post, we will discuss how we can use email alerts in flows to send emails to user.

Please check below video for more detailed explaination :

Problem Statement: Whenever status of case changes to Escalated, send an emal to user.

If you have any questions related to this topic, please add them in comments section of the video.

Lightning Flows in Salesforce: How To Manage Flow Versions And Access to Flows| Restrict User Access

In this post we will discuss,

  1. How we can manage the flow versions.
  2. How we can restrict user access on flows.
  3. How we can deactivate flows in salesforce.
  4. How we can create new version or new flow from existing flows in salesforce.
  5. We will look into flow properties.

Please check below video for more details on this topic :

If you have any questions related to this topic, please add them in comments section of the video.

Lightning Flows in Salesforce: How to Upload Files Using Flows in Salesforce?

Under this topic, We discuss how we can Upload Files using Salesforce Lightning Flows.

Problem Statement:

Create a case from Account record using quick action and attach file along with case.

Please check below video for detailed explaination with examples on uploading files using lightning flows in salesforce:

If you have any questions related to this topic, please add them in comments section of the video.

Lightning Flows in Salesforce: How to Call Flows Using Quick Actions in Salesforce?

To use flow inside quick actions in Salesforce we need to follow below steps:

  1. Create a flow to be used in quick action.
  2. Create a recordId variable resource which will be accepting recordId as input.
  3. Create a Quick action from buttons, link and actions on object and select action type as flow.
  4. Include the flow name in the action.
  5. Include the Quick Action inside Salesforce Mobile and Lightning Experience Acions section in Page layout.

Please check below video for more detailed explaination :

If you have any questions related to this topic, please add them in comments section of the video.

Lightning Flows in Salesforce: How to Delete a Record Using Flows in Salesforce

Under this topic, we discuss how we can delete a Salesforce Record using Flows.

Problem Statement : Delete a case record when status of case is updated to closed.

Please check below video for more detailed explaination with help of example:

If you have any questions related to this topic, please add them in comments section of the video.

Lightning Flows in Salesforce: Condition Elements, Loops and Assignments in Lightning Flows

Under this topic, we discuss how we can create an auto-launch flow. How we can call auto-launch flow from process builder.

Further, we discuss, how we can use:

1. Decision element

2. Loop Element.

3. Assignment Element.

We understand that by taking a problem statement and providing a solution for it.

Problem Statement:

When ‘Customer Priority’ field on Account is updated, update the ‘Priority’ field of all related cases having ‘Status’ as ‘New’ with same value.

Please check below video for more detailed explaination :

If you have any questions related to this topic, please add them in comments section of the video.