Close Menu
SalesforceCodex
    Facebook X (Twitter) Instagram
    Trending
    • How to Build a Generic Modal Window in Lightning Web Component
    • Top 10 Salesforce Flow Features of Salesforce Summer ’25
    • Unlock the Power of Vibe Coding in Salesforce
    • How to Implement Dynamic Queueable Chaining in Salesforce Apex
    • How to Implement Basic Queueable Chaining in Salesforce Apex
    • How to Suppress PMD Warnings in Salesforce Apex
    • Top 10 PMD Issues Salesforce Developers Should Focus on in Apex
    • How to Use Graph API for Outlook-Salesforce Connection
    Facebook X (Twitter) Instagram
    SalesforceCodex
    Subscribe
    Saturday, May 31
    • Home
    • Architecture
    • Salesforce
      • News
      • Apex
      • Integration
      • Books Testimonial
    • Questions
    • Certification
      • How to Prepare for Salesforce Integration Architect Exam
      • Certification Coupons
    • Integration Posts
    • Downloads
    • About Us
      • Privacy Policy
    SalesforceCodex
    Home»Salesforce»Integrate Salesforce Stackexchange using Lightning Web Component and Apex

    Integrate Salesforce Stackexchange using Lightning Web Component and Apex

    Dhanik Lal SahniBy Dhanik Lal SahniOctober 2, 2019Updated:October 2, 20192 Comments3 Mins Read
    Facebook Twitter Pinterest LinkedIn Tumblr Email
    Integrate Salesforce Stackexchange using Lightning Web Component and Apex
    Share
    Facebook Twitter LinkedIn Pinterest Email

    Salesforce Stack Exchange is dedicated community site for Salesforce developer to get answers of all question. This community has lot of members who helps in resolving issues.  This post is showing how we can get list of all members of this community.

    We are using Salesforce Stack Exchange API to get members list using Apex. Members list is being shown using Lightning Web Component in lightning community.  I have named this community as Salesforce Stackexchange User Explorer  and can be accessed at https://dhanik-stackoverflow-developer-edition.ap15.force.com/stackexplorer/s/

    Salesforce Stack Exchange API :

    https://api.stackexchange.com/2.2/users API is used to get user list in Apex. We can pass different parameter to this API to get required list. We can do sorting, pagination as well as we can get list of members from other group as well like freelancing, stackoverflow etc.

    Apex Code to get members list


    We have to create wrapper class to get members list. Wrapper class can be created using https://json2apex.herokuapp.com/

    Lightning Web Component to show users

    Let us create Lightning Web Component to show list of members. I have created two combo box in this component. One combo box is showing group name like salesforce, stackoverflow and freelancing for which we need to show user.

    <lightning-combobox name="progress" label="Stack Exchange Group"
     value="" placeholder="Select Group" options={options} onchange={handleChange}
    required></lightning-combobox>
     get options() {
            return [
                { label: 'Salesforce', value: 'salesforce' },
                { label: 'Stackoverflow', value: 'stackoverflow' },
                { label: 'Freelancing', value: 'freelancing' },
            ];
        }
    

    Second combo will show order field name.

    <lightning-combobox name="progress" label="Order By" value="" placeholder="Select Field"
    options={fields}  onchange={handleFieldChange} required></lightning-combobox>
     get fields() {
            return [
                { label: 'Reputaion', value: 'reputation' },
                { label: 'Name', value: 'name' }
            ];
        }
    

    I have used lightning-datatable to show members list in grid.

    <lightning-datatable key-field="id" data={data} show-row-number-column=false hide-checkbox-column  columns={columns}></lightning-datatable>

    We have to show creation date and badge count on table. For this we have to change JSON data and date format after receiving from Apex.

    .then(result => {
                for (let i = 0; i < result.items.length; i++) {
                    let row = result.items[i];
                    row.silver = row.badge_counts.silver; 
                    row.gold = row.badge_counts.gold;
                    row.bronze = row.badge_counts.bronze;  //create field from dependent object
                    row.date = new Date(parseInt(row.creation_date.substr(6)));  //Format date
                }
                this.data = result.items;
                this.error = undefined;
                console.log(result.items);
            })
    

    Complete Code of this component

    Lightning Web Component for Pagination

    We have to create pagination button like next, previous to get next pagination records. I have created another lightning web  component for this. Handler of these button is passed from main lightning web component.

    Complete Code of this component

    Demo Time:

    Reference:

    https://api.stackexchange.com/docs/users

    https://developer.salesforce.com/docs/component-library/overview/components

    apex Lightning web component lwc
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email
    Previous ArticleCapture Image using WebCAM in Lightning Component
    Next Article Show Image in Lightning Web Component Data Table
    Dhanik Lal Sahni
    • Website

    Related Posts

    By Dhanik Lal Sahni4 Mins Read

    How to Build a Generic Modal Window in Lightning Web Component

    May 26, 2025
    By Dhanik Lal Sahni6 Mins Read

    Top 10 Salesforce Flow Features of Salesforce Summer ’25

    May 11, 2025
    By Dhanik Lal Sahni6 Mins Read

    Unlock the Power of Vibe Coding in Salesforce

    April 30, 2025
    View 2 Comments

    2 Comments

    1. Ram on September 12, 2022 12:10 pm

      Hi DHANIK, Thank you for that awesome post, just a quick question I need your help with, for the field that has image , is it returning an HTML tag, like for example ( ) and you reading it, if not , do you know how to read that HTML stage from formula field, please?

      Reply
      • Dhanik Lal Sahni on September 14, 2022 6:59 pm

        Hello,

        Not able to understand your query. Please provide one example of the issue.

        Thank You,
        Dhanik

        Reply
    Leave A Reply Cancel Reply

    Ranked #1 SALESFORCE DEVELOPER BLOG BY SALESFORCEBEN.COM
    Featured on Top Salesforce Developer Blog By ApexHours
    Recent Posts
    • How to Build a Generic Modal Window in Lightning Web Component
    • Top 10 Salesforce Flow Features of Salesforce Summer ’25
    • Unlock the Power of Vibe Coding in Salesforce
    • How to Implement Dynamic Queueable Chaining in Salesforce Apex
    • How to Implement Basic Queueable Chaining in Salesforce Apex
    Ranked in Top Salesforce Blog by feedspot.com
    RSS Recent Stories
    • How to Connect Excel to Salesforce to Manage Your Data and Metadata February 9, 2025
    • Difference Between With Security and Without Security in Apex January 2, 2025
    • Top Reasons to Love Salesforce Trailhead: A Comprehensive Guide December 5, 2024
    • How to Utilize Apex Properties in Salesforce November 3, 2024
    • How to Choose Between SOQL and SOSL Queries July 31, 2024
    Archives
    Categories
    Tags
    apex (111) apex code best practice (8) apex rest (11) apex trigger best practices (4) architecture (22) Asynchronous apex (9) AWS (5) batch apex (9) batch processing (4) code optimization (8) code review tools (3) custom metadata types (5) design principle (9) file upload (3) flow (15) future method (4) google (6) google api (4) integration (19) integration architecture (6) lighting (8) lightning (64) lightning-combobox (5) lightning-datatable (10) lightning component (30) Lightning web component (62) lwc (51) named credential (8) news (4) optimize apex code (4) Permission set (4) pmd (3) Queueable (9) rest api (23) S3 Server (4) salesforce (141) salesforce apex (46) salesforce api (4) salesforce api integration (5) Salesforce Interview Question (4) salesforce news (5) salesforce question (5) solid (6) tooling api (5) Winter 20 (8)

    Get our newsletter

    Want the latest from our blog straight to your inbox? Chucks us your detail and get mail when new post is published.
    * indicates required

    Ranked #1 SALESFORCE DEVELOPER BLOG BY SALESFORCEBEN.COM
    Featured on Top Salesforce Developer Blog By ApexHours
    Recent Posts
    • How to Build a Generic Modal Window in Lightning Web Component
    • Top 10 Salesforce Flow Features of Salesforce Summer ’25
    • Unlock the Power of Vibe Coding in Salesforce
    • How to Implement Dynamic Queueable Chaining in Salesforce Apex
    • How to Implement Basic Queueable Chaining in Salesforce Apex
    Ranked in Top Salesforce Blog by feedspot.com
    RSS Recent Stories
    • How to Connect Excel to Salesforce to Manage Your Data and Metadata February 9, 2025
    • Difference Between With Security and Without Security in Apex January 2, 2025
    • Top Reasons to Love Salesforce Trailhead: A Comprehensive Guide December 5, 2024
    • How to Utilize Apex Properties in Salesforce November 3, 2024
    • How to Choose Between SOQL and SOSL Queries July 31, 2024
    Archives
    Categories
    Tags
    apex (111) apex code best practice (8) apex rest (11) apex trigger best practices (4) architecture (22) Asynchronous apex (9) AWS (5) batch apex (9) batch processing (4) code optimization (8) code review tools (3) custom metadata types (5) design principle (9) file upload (3) flow (15) future method (4) google (6) google api (4) integration (19) integration architecture (6) lighting (8) lightning (64) lightning-combobox (5) lightning-datatable (10) lightning component (30) Lightning web component (62) lwc (51) named credential (8) news (4) optimize apex code (4) Permission set (4) pmd (3) Queueable (9) rest api (23) S3 Server (4) salesforce (141) salesforce apex (46) salesforce api (4) salesforce api integration (5) Salesforce Interview Question (4) salesforce news (5) salesforce question (5) solid (6) tooling api (5) Winter 20 (8)

    Get our newsletter

    Want the latest from our blog straight to your inbox? Chucks us your detail and get mail when new post is published.
    * indicates required

    Facebook X (Twitter) Instagram Pinterest YouTube Tumblr LinkedIn Reddit Telegram
    © 2025 SalesforceCodex.com. Designed by Vagmine Cloud Solution.

    Type above and press Enter to search. Press Esc to cancel.

    Ad Blocker Enabled!
    Ad Blocker Enabled!
    Our website is made possible by displaying online advertisements to our visitors. Please support us by disabling your Ad Blocker.