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
Kiran Jain 15Kiran Jain 15 

How to fetch object Icon with object Api Name + apex

Hello Experts,
I want to fetch object icon with object api Name using apex. I have tried  with  following code and I am also getting objects Name and its icon but Problam is that Icon name is not coming Properly. some Icon is coming but some icon is not.
Actually I am fetching all objects that is referanced with related to(WhatId) Fields of Task Object.
public with sharing class MultiObjectLookupControllerV1 {
    public static Map < String, String > mapRefObjApiWiseLabel;
    @AuraEnabled(cacheable = true)
    public static lookupWrapper fetchLookupWrapper(){
        lookupWrapper olookupWrapper = new lookupWrapper();
        olookupWrapper.ObjectsMap = MultiObjectLookupControllerV1.TaskReltedToObjects();
        olookupWrapper.objectApiWiseIcon = MultiObjectLookupControllerV1.fetchObjectsIcon();
        return olookupWrapper; 
        
    } 
    
    private static map<string,string> fetchObjectsIcon(){
        map<string,string> mapObjectsWiseIcons = new map<string,string>();
        
        List<Schema.DescribeTabSetResult> tabSetDesc = Schema.describeTabs();
        
        List<Schema.DescribeTabResult> tabDesc = new List<Schema.DescribeTabResult>();
        Map<string,List<Schema.DescribeIconResult>> mapSchemaObjWiseIconDescri = new Map<string,List<Schema.DescribeIconResult>>();

        for(Schema.DescribeTabSetResult tsr : tabSetDesc) { 
            tabDesc.addAll(tsr.getTabs());
        }
		Map<String,String> mapObjects = mapRefObjApiWiseLabel;
        set<string> lstObjects = mapObjects.keySet();
        system.debug('lstObjects : ' + lstObjects.size());
        system.debug('tabDesc : ' + tabDesc.size());
        
        integer count= 0;
       set<string> setUniqueObj = new set<string>();
        for(Schema.DescribeTabResult tr : tabDesc) {
            system.debug('sobjectName : ' + tr.getSobjectName());
            if( lstObjects.Contains(tr.getSobjectName()) ) {
                if(!setUniqueObj.contains(tr.getSobjectName())){
                setUniqueObj.add(tr.getSobjectName());
                if( tr.isCustom() == true ) {
                     mapSchemaObjWiseIconDescri.put(tr.getSobjectName(),tr.getIcons());
                } else {
                    if(tr.getSobjectName() == 'Order'){
                       system.debug('tr.getIcons() : ' + tr.getIcons()); 
                        system.debug('tr : ' + tr); 
                    }
                    system.debug('tr.getSobjectName() : ' + tr.getSobjectName());
                    mapObjectsWiseIcons.put(tr.getSobjectName(),'standard:' + tr.getSobjectName().toLowerCase());
                    }
                
               }
            }
            }
       
        
        system.debug('setUniqueObj :  ' + setUniqueObj.size());
        system.debug('mapObjectsWiseIcons size : ' + mapSchemaObjWiseIconDescri.size());
        system.debug('mapObjectsWiseIcons size : ' + mapObjectsWiseIcons.size());
      
        
        for(string obj : lstObjects){
        if(mapSchemaObjWiseIconDescri.containsKey(obj)){
        for(Schema.DescribeIconResult ir : mapSchemaObjWiseIconDescri.get(obj)){
            //if (ir.getContentType() == 'image/svg'){ 
            if (ir.getContentType() == 'image/svg+xml'){
                string cObjIconData = 'custom:' + ir.getUrl().substringBetween('custom/','.svg').substringBefore('_');
                 mapObjectsWiseIcons.put(obj,cObjIconData);
               } 
        }
        }
       }
         
        system.debug('mapObjectsWiseIcons size() : ' + mapObjectsWiseIcons.size());
        system.debug('mapObjectsWiseIcons : ' + mapObjectsWiseIcons);
        return mapObjectsWiseIcons;
    }
    
   
    private static  Map<String,String> TaskReltedToObjects() {
         mapRefObjApiWiseLabel = new Map < String, String >();
        
		Schema.DescribeFieldResult f = Schema.sObjectType.Task.fields.WhatId;
		for(Schema.SObjectType reference : f.getReferenceTo()) {
            string objApiName = reference.getDescribe().getName();
            string objLabel = reference.getDescribe().getLabel();
            string objLabelPlural = reference.getDescribe().getLabelPlural();
   			if(objApiName != 'Goal' && 
               objApiName != 'LocationWaitlistedParty' && 
               objApiName != 'WorkCoaching' && 
               objApiName != 'Metric'){
		mapRefObjApiWiseLabel.put( objApiName, objLabelPlural );
               }
		}

		system.debug('mapReferenceObjects size() : ' + mapRefObjApiWiseLabel.size());
        system.debug('mapReferenceObjects : ' + mapRefObjApiWiseLabel.keyset());
        return mapRefObjApiWiseLabel;
    }

    public class lookupWrapper{
        @AuraEnabled  public Map<String,String> ObjectsMap;
        @AuraEnabled  public Map<String,String> objectApiWiseIcon;
        }
}


above is my apex code. I am getting all referanced object of related to field but when It comes to Icon, only some Icon is getting. I want both custom object and standard object Icon.

If I get Order Object than its icon is coming standard:order whereas orignal Icon name is standard:orders that is referance following link.

https://www.lightningdesignsystem.com/icons/
I want all Icon Name so that I could show that in lookup. I am building a lookup Like Related to Field Of Task Object.


Thanks In Advance