Home SalesforceApex sObject Tab icon in Salesforce Apex

sObject Tab icon in Salesforce Apex

by Dhanik Lal Sahni

We need to show sObject tab icon in listbox or lookup for showing records. An icon will help us identify the type of data easily. We can show tab icons using LWC’s lightning-icon and AURA’s lightning:icon element.

Use Case:

I was preparing a custom lookup element to show data as a picklist. Based on the passed object name I was showing data in custom lookup. Along with data, we need to show the respective sObject icon also based on the passed object name in the custom picklist.


We have metadata describing classes Schema.DescribeTabResult, Schema.DescribeTabSetResult and Schema.DescribeIconResult which will help us in getting icon detail.

public class sObjectSelector {
    public static String getIconName(String 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('_');
        return u;

Show Icon in Lightning Web Component

Test Page:


Get sobject tab icon

Related Post

What are Salesforce Big Objects?

You may also like

Leave a Comment

Salesforce Summer’22 Enhancement in Nonprofit and Education Salesforce Summer’22 Enhancement in Loyalty, Public Sector, Media, Energy & Utilities Salesforce Summer’22 Enhancement in Health, Manufacturing, Consumer Goods Cloud Salesforce Summer’22 Enhancement in Financial Cloud Salesforce Summer’22 Enhancement for Platform UI