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
adi salesforceadi salesforce 

How to display rating picklist values in a row and industry picklist values in a column and display corresponding no.of records to related to both rating and industry.

Niraj Kr SinghNiraj Kr Singh
Hi Adi,
you can try this code
Might be needed some change in VF code

Class:
public with sharing class TBN_PicklistReport {
	//Variables
	public Map<String, map<String, Integer>> ratingVsRecordCountMapOfmap { get;set; }
	List<SObject> lstSobjectResult;
	String piklistName;
	String objName;
	
	
	public TBN_PicklistReport() {
		//Do-Initialization
		ratingVsRecordCountMapOfmap = new Map<String, map<String, Integer>>();
		lstSobjectResult = new List<SObject>();
		piklistName = 'StageName';
		objName = 'Opportunity';
        getRecordCounts();
	}
	
	
    public void getRecordCounts() {	
    	String objName = 'Task'; //ApexPages.currentPage().getParameters().get('objectName');
        String piklistNameRow = 'Priority'; //Apexpages.currentPage().getParameters().get('picklist1');
        String piklistNameCol = 'Status'; //Apexpages.currentPage().getParameters().get('picklist2');
        
        system.debug('--objName--' + objName);
        system.debug('--piklistNameRow--' + piklistNameRow);
		system.debug('--piklistNameCol--' + piklistNameCol);
        //Get all picklist value from schema
		Map<String, String> mapAPInameVsLabelRow = getSchemaPicklist(objName, piklistNameRow);
		Map<String, String> mapAPInameVsLabelCol = getSchemaPicklist(objName, piklistNameCol);
		//Initialize all Priority and Status combinations by Zero.
		for(String strKeyRow : mapAPInameVsLabelRow.keySet()) {
			Map<String, Integer> mapKeyColVsValue = new Map<String, Integer>();
			for(String strKeyCol : mapAPInameVsLabelCol.keySet()) {
				mapKeyColVsValue.put(mapAPInameVsLabelCol.get(strKeyCol), 0);
			}
			ratingVsRecordCountMapOfmap.put(mapAPInameVsLabelRow.get(strKeyRow),mapKeyColVsValue);
		}
		
		//Get all Task for Priority, Status
		lstSobjectResult = [Select Priority, Status From Task Where Priority != Null AND Status != Null];
		if(!lstSobjectResult.isEmpty()) {
			for(SObject objTest : lstSobjectResult) {
                String priorityPicklistVal = (String)objTest.get(piklistNameRow);
                String statusPicklistVal = (String)objTest.get(piklistNameCol);
				if(ratingVsRecordCountMapOfmap.containsKey(priorityPicklistVal)) {
					Map<String, Integer> innermap = ratingVsRecordCountMapOfmap.get(priorityPicklistVal);
					//if(!innermap.isEmpty()) {
						if(innermap.containsKey(statusPicklistVal)) {
							Integer count = innermap.get(statusPicklistVal) + 1;
							innermap.put(statusPicklistVal, count);
						}
						else {
							innermap.put(statusPicklistVal, 1);
						}
						ratingVsRecordCountMapOfmap.put(priorityPicklistVal, innermap);
					//}
				}
				else {
					Map<String, Integer> innermap = new Map<String, Integer>();
					innermap.put(statusPicklistVal, 1);
					ratingVsRecordCountMapOfmap.put(priorityPicklistVal, innermap);
				}
			}
		}
		system.debug('---> ' + ratingVsRecordCountMapOfmap);
		//return ratingVsRecordCountMapOfmap;
	}
	
	private Map<String, String> getSchemaPicklist(String objName, String piklistName) {
		
		Map<String, Schema.SObjectField> objectFields = Schema.getGlobalDescribe().get(objName).getDescribe().fields.getMap();
		List<Schema.PicklistEntry> ple = objectFields.get(piklistName).getDescribe().getPicklistValues();
		Map<String, String> mapAPInameVsLabel = new Map<String, String>();
		for( Schema.PicklistEntry pickListVal : ple){
			//pickListLabelsList.add(pickListVal.getLabel());
			//pickListValuesList.add(pickListVal.getValue());
			mapAPInameVsLabel.put(pickListVal.getValue(), pickListVal.getLabel());
		}
		return mapAPInameVsLabel;
	}
}
Visualforce Page:
<apex:page controller="TBN_PicklistReport">
    <apex:form >
        <apex:pageBlock >
            <apex:outputPanel rendered="{!IF(ratingVsRecordCountMapOfmap == NULL, false, true)}">
                <apex:repeat value="{!ratingVsRecordCountMapOfmap}" var="mapKey"> <br/>
                    {!mapKey} &nbsp;&nbsp;
                    <apex:repeat value="{!ratingVsRecordCountMapOfmap[mapKey]}" var="innerMapKey">
                        	<!--{!innerMapKey} --> <!-- It will show header-->
                            {!ratingVsRecordCountMapOfmap[mapKey][innerMapKey]} &nbsp;&nbsp;
                    </apex:repeat> <br/>
                </apex:repeat>
				<apex:commandButton value="Back" onclick="window.location.top.reload();" />
            </apex:outputPanel>
        </apex:pageBlock>
    </apex:form>
</apex:page>



Let me know if it works for you.
Thanks
Niraj
adi salesforceadi salesforce
Hi,
Thank you Niraj for giving the solution but the requirement I want to display vf page like this.  it should look like table.

                    new    working     escalated
high             1            2              0
 low               5          1              2
medium        0           5              4