Skip to main content

Displaying User Level’s Dynamically In Lightning Web Component


 Agenda

I am writing this blog, to display dynamic user data beautifully, It enables each user to see the users they need to report. With this dynamic component, you can control data visibility without having to create a separate component as well, with its own running user. 

Now, It’s time to show the user’s of our organization dynamically their role in a beautiful way.


How does it work?

You fetch the User’s record with a simple Apex SOQL query and just displaying details Dynamically over a Lightning Web Component, And place that component where ever you want.


Requirements:

  • You need to have access to your org.
  • Should have the VS Code Installed in your system.

  • You should have some basic knowledge of Lightning Web Component.

About Lightning Web Component (LWC):


Lightning Web Components are lightweight custom elements based on native HTML and Modern JavaScript.


Lightning Web Component or LWC are custom HTML elements built using HTML and modern JavaScript. We Basically work on ES6(ECMAScript 2015). LWC uses core Web Components standards and delivers exceptional performance.


A Lightning web component that renders UI must include an HTML file, a JavaScript file, and a metadata configuration file. But we can create CSS and SVG file’s also as per our needs.


Start Working On Agenda:

First, Create a Simple Apex Class (name it as you wish) and use that class to fetch the records of users you need to display on the hierarchy.


We need to create a method in the class and make it AuraEnabled to access it in the Component.


And this method return’s the list of users we request with the help of the User Id List. And This method returns the list of required fields.



<! ----- Apex Class ----- >


LWC (HTML PORTION)


Now, Create a Lightning Web Component (name it as you wish), I name It as an app. 

The HTML file of the component is app.html. It has a div which contains some classes.

Our aim is to change the CSS class of div for every different user and display it beautifully.


We are getting User Data in a List and we render a list of users, using for:each directive

In the template. We can call it for loop in LWC. Use for:item=” current item” to access

the current item.

We are Using Img <img src=” User Photo”/> to show the User’s Profile Picture.

For Displaying Level we are using the “ index method ” function which is getting

the sequence of numbers from the JavaSript file of the Component.


And the main part the Styling one, for that we are using the “ user style ” method to

get the styling from the CSS file of the component.


<! ----- App.html----- >





                                                              <! ----- App.Css----- >

The CSS file Displays styling according to different users.


LWC (JAVASCRIPT PORTION)


                                                         <! ----- App.js----- >


And, Here Is our Resulting Output:





Thank You and Regards

Rahul Vaishnav




Comments

  1. its very useful for me thank you rahul vaishanv

    ReplyDelete
  2. Thanks Rahul , It is really helpful for me and I found it quite similar with my business requirement.

    ReplyDelete

Post a Comment

Popular posts from this blog

Using Data - Attributes in Lightning Web Component (LWC)`

  Agenda      While working with Salesforce data we need to play with Id’s (Identifiers). An ID can be associated with a Record or with a specifier. While working with records when we need to make changes or view any particular record details, we need their ID’s, as I describe in my previous blog’s how can we show or edit any salesforce record with the help of Basic components of Salesforce.  To create forms that let users view, edit, and create Salesforce records, use Lightning-record-form, Lightning-record-edit-form, and Lightning-record-view form components. And To use these components we need Salesforce Record ID. Blog Details This Blog gives us a brief about how can we get a particular record Id or value after any event using Data - Attributes.  What we are going to do In this blog, we use Data - Attribute functionality from HTML5  in our Lightning Web Component and use data attribute to get...

Select - Deselect checkbox in Lightning Web Component

  Agenda In the previous blog, we are working with a single record and manipulating it as per the requirements, but when we are working for the organization we need to think to cover larger aspects. And while working with salesforce data we should be aware of the fact that we might need to work with data in bulk. So, when we need to work with more than one record we use checkbox functionality and use that checkbox to see which record we need to make changes to. Blog Details The blog gives us a brief that how we select and unselect all checkboxes from the header checkbox. What we are going to do In this blog, we use a table to show the records with the checkbox for each record and a header checkbox to select - unselect all records. Requirements: You need to have access to your org.     Should have installed the VS Code Installed in your system.    You should have some basic knowledge of Lightning Web Component. You must have some proper records ...