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
Chirag_JoshiChirag_Joshi 

Cannot retrieve value of map from List of Map in <apex:pageblocktable> columns except 'Name'

VF Page:
<apex:page controller="FLSController2">
    <apex:form >
        <apex:pageBlock title="FLS Test" >
            <apex:inlineEditSupport event="onDblClick"/>
            <apex:pageMessages />
            <apex:pageBlockTable value="{!acc}" var="a">
                <apex:column headerValue="Account Name" value="{!a['Name']}" rendered="{!$ObjectType.Account.Fields.Name.Accessible}"/>
                <apex:column headerValue="Phone" value="{!a['Phone']}" rendered="{!$ObjectType.Account.Fields.Phone.Accessible}"/>
                <apex:column headerValue="Industry" value="{!a['Industry']}" rendered="{!$ObjectType.Account.Fields.Industry.Accessible}"/>
                <apex:column headerValue="Rating" value="{!a['Rating']}" rendered="{!$ObjectType.Account.Fields.Rating.Accessible}"/>
                <apex:column headerValue="Type" value="{!a['Type']}" rendered="{!$ObjectType.Account.Fields.Type.Accessible}"/>
            </apex:pageBlockTable>
        </apex:pageBlock>
    </apex:form>
</apex:page>

Apex Controller:
public with sharing class FLSController2 {
	
    public List<Map<String, String>> acc;
    
    public FLSController2(){
       acc = new List<Map<String, String>>();
    }
    
    public List<Map<String, String>> getacc(){
    
    	List<Account> aList = [SELECT Name, Industry, Phone, Rating, Type FROM Account];
        for(Account a: aList){
            Map<String, String> m = new Map<String, String>();
            m.put('Name', a.Name);
            m.put('Industry', a.Industry);
            m.put('Phone', a.Phone);
            m.put('Rating', a.Rating);
            m.put('Type', a.Type);
            acc.add(m);
        }
        return acc;
    }
}

Error:
User-added image
Best Answer chosen by Chirag_Joshi
K SrikanthK Srikanth

Hello Chirag,

You are getting exception due to null values. Keep null check before putting the values in list.

Regards,
Srikath K

All Answers

K SrikanthK Srikanth

Hello Chirag,

You are getting exception due to null values. Keep null check before putting the values in list.

Regards,
Srikath K

This was selected as the best answer
Chirag_JoshiChirag_Joshi
Thanks! that worked

Updated VF Page:
<apex:page controller="FLSController2">
    <apex:form >
        <apex:pageBlock title="FLS Test" >
            <apex:pageBlockTable value="{!acc}" var="a">
                <apex:column headerValue="Account Name" value="{!a['Name']}" rendered="{!$ObjectType.Account.Fields.Name.Accessible}"/>
                <apex:column headerValue="Phone" value="{!a['Phone']}" rendered="{!$ObjectType.Account.Fields.Phone.Accessible}"/>
                <apex:column headerValue="Industry" value="{!a['Industry']}" rendered="{!$ObjectType.Account.Fields.Industry.Accessible}"/>
                <apex:column headerValue="Rating" value="{!a['Rating']}" rendered="{!$ObjectType.Account.Fields.Rating.Accessible}"/>
                <apex:column headerValue="Type" value="{!a['Type']}" rendered="{!$ObjectType.Account.Fields.Type.Accessible}"/>
            </apex:pageBlockTable>
        </apex:pageBlock>
    </apex:form>
</apex:page>

Updated Apex Controller:
public with sharing class FLSController2 {
	
    public List<Map<String, String>> acc;
    
    public FLSController2(){
       acc = new List<Map<String, String>>();
    }
    
    public List<Map<String, String>> getacc(){
    
    	List<Account> aList = [SELECT Name, Industry, Phone, Rating, Type FROM Account];
        for(Account a: aList){
            Map<String, String> m = new Map<String, String>();
            m.put('Name', a.Name);
            if(a.Industry != null){
                m.put('Industry', a.Industry);
            }else{
                m.put('Industry', '');
            }
            if(a.Phone != null){
                m.put('Phone', a.Phone);
            }else{
                m.put('Phone', '');
            }
            if(a.Rating != null){
                 m.put('Rating', a.Rating);
            }else{
                m.put('Rating', '');
            }
            if(a.Type != null){
                m.put('Type', a.Type);
            }else{
                m.put('Type', '');
            }            
            acc.add(m);
        }
        return acc;
    }
}