function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

Get Object icon in lwc

I'm trying to display the current object icon in my lwc. Any ideas?

User-added image
SwethaSwetha (Salesforce Developers) 
HI Satya,
Do you see any error in the browser console?

If not, you can try approachof using lightning/uiObjectInfoApi to get the icon information for any custom object, following is pseudo code for Account object:
import { LightningElement, wire } from 'lwc';
import { getObjectInfo } from 'lightning/uiObjectInfoApi';
import ACCOUNT_OBJECT from '@salesforce/schema/Account';

@track themeInfo;

export default class Example extends LightningElement {
    @wire(getObjectInfo, { objectApiName: ACCOUNT_OBJECT })
    handleResult({error, data}) {
        if(data) {

            let objectInformation = data;

            // access theme info here
            // icon URL is availe as themeInfo.iconUrl
            this.themeInfo = objectInformation.themeInfo || {};
        if(error) {
            // handle error

To display dynamic icon URL, you can try themeInfo of uiObjectInfoApi. 


Hope this helps you. Please mark this answer as best so that others facing the same issue will find this information useful. Thank you
Hi Swetha,

Thanks for your reply. I will check this and get back. 

I tried the below and was able to get it dynamically for standard and Custom objects. 

import getIconName from '@salesforce/apex/RelatedListController.getIconName';
export default class Example extends ExampleOne(LightningElement) {
@wire(getIconName, {sObjectName: '$objectApiName'})
    gettingiconName({ error, data }) {
        if (data) {
            this.iconName = data;
        else if (error) {
            console.log('Error is ' + JSON.stringify(error));


<div class="slds-media__figure">
                    <span class="slds-icon_container slds-icon-standard-contact" title={objName}>
                            <lightning-icon icon-name={iconName} size="small"></lightning-icon>
                        <span class="slds-assistive-text">{objName}</span>

Apex Controller:
    public static String getIconName(String sObjectName){
        system.debug('sObjectName:: '+sObjectName);
        String u;
        List<Schema.DescribeTabSetResult> tabSetDesc = Schema.describeTabs();
        List<Schema.DescribeTabResult> tabDesc = new List<Schema.DescribeTabResult>();
        List<Schema.DescribeIconResult> iconDesc = new List<Schema.DescribeIconResult>();

        for(Schema.DescribeTabSetResult tsr : tabSetDesc) { tabDesc.addAll(tsr.getTabs()); }

        for(Schema.DescribeTabResult tr : tabDesc) {
            if( sObjectName == tr.getSobjectName() ) {
                if( tr.isCustom() == true ) {
                } else {
                    u = 'standard:' + sObjectName.toLowerCase();
        for (Schema.DescribeIconResult ir : iconDesc) {
            if (ir.getContentType() == 'image/svg+xml'){
                u = 'custom:' + ir.getUrl().substringBetween('custom/','.svg').substringBefore('_');
        system.debug('iconName:: '+u);
        return u;