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
Raghu.2020Raghu.2020 

Get Object icon in lwc

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

Example:
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. 

Reference: https://salesforce.stackexchange.com/questions/268249/soql-query-or-other-means-to-get-the-icon-assigned-to-an-object

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

Thanks for your reply. I will check this and get back. 
Raghu.2020Raghu.2020
Hi, 

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

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

    }
}

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

Apex Controller:
@AuraEnabled(cacheable=true)
    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 ) {
                    iconDesc.addAll(tr.getIcons());
                } else {
                    u = 'standard:' + sObjectName.toLowerCase();
                }
            }
        }
        for (Schema.DescribeIconResult ir : iconDesc) {
            if (ir.getContentType() == 'image/svg+xml'){
                u = 'custom:' + ir.getUrl().substringBetween('custom/','.svg').substringBefore('_');
                break;
            }
        }
        system.debug('iconName:: '+u);
        return u;
    }