vijayk3327 / LWC

1 stars 0 forks source link

Using Wrapper Class in Lightning Web Component to retrieve list of records of Opportunity Object in Salesforce LWC #82

Open vijayk3327 opened 1 year ago

vijayk3327 commented 1 year ago

In this post we are going to learn about How to retrieve list of records of Opportunity Object uses of Wrapper Class in Salesforce LWC – Lightning Web Component.

A wrapper class is a collection of different Salesforce data types. In Salesforce, you can combine multiple data types and utilize them for various purposes.

→ Get source code live demo link:-

Step 1:- Create Lightning Web Component : lwcWrapperClass.html

` `

Step 2:- Create Lightning Web Component : lwcWrapperClass.js

` import { LightningElement,wire } from 'lwc'; import fetchOppData from '@salesforce/apex/lwcWrapperClassCtrl.fetchOppData'

export default class LwcWrapperClass extends LightningElement { @wire(fetchOppData) oppData; }`

Step 3:- Create Lightning Web Component : lwcWrapperClass.js-meta.xml ` <?xml version="1.0" encoding="UTF-8"?>

45.0 true lightning__AppPage lightning__RecordPage lightning__HomePage ` **Step 4:- Create Style CSS : lwcWrapperClass.css** ` table.tblColPad th{background:#ddd;} table.tblColPad th, table.tblColPad td {padding:5px !important;}` **Step 5:- Create Apex Controller : lwcWrapperClassCtrl.cls** ` public with sharing class lwcWrapperClassCtrl { @AuraEnabled(cacheable=true) public static ListfetchOppData() { List wrapperOppList=new List(); for(Opportunity opp:[SELECT Id, Name, Amount, AccountId, Account.Name, CloseDate, Description, StageName, LeadSource,Type FROM Opportunity LIMIT 10]) { WrapperClass wrapItemFld=new WrapperClass(); wrapItemFld.Name=opp.Name; wrapItemFld.StageName=opp.StageName; wrapItemFld.Description=opp.Description; wrapItemFld.LeadSource=opp.LeadSource; wrapItemFld.Type=opp.Type; wrapperOppList.add(wrapItemFld); } return wrapperOppList; } public class WrapperClass { @AuraEnabled public String Name; @AuraEnabled public String StageName; @AuraEnabled public String Description; @AuraEnabled public String LeadSource; @AuraEnabled public String Type; } }` **Step 6:- Create Lightning Application : lwcWrapperClassApp.app** ` ` **[→ Get source code live demo link:-](https://www.w3web.net/wrapper-class-to-retrieve-data-in-lwc/)**