+ Start a Discussion
Vijay Kumar Rebbala 11Vijay Kumar Rebbala 11 

Map values doesn't show on Visualforcepage

<apex:page controller="Testctrl">
    <apex:form >
        <apex:repeat value="{!attdmap}" var="attdkey" >
            <apex:OutputText value="{!attdkey}"/>
            <apex:OutputText value="{!attdmap[attdkey]}"/>
       </apex:repeat>
    </apex:form>
</apex:page>



public class Testctrl {
    public list<Student__c> acctlist {get;set;}
    public Map<Student__c, Boolean> attdmap{get;set;}
     
    public Testctrl(){
        Map<Student__c, Boolean> attdmap = new Map<Student__c, Boolean>();
        acctlist = [SELECT Id, Name FROM Student__c];
        for(Student__c atu23 : acctlist){
        attdmap.put(atu23,false);
        }        
    }

}
Best Answer chosen by Vijay Kumar Rebbala 11
logontokartiklogontokartik
Well I see the problem now. You are not populating the attdmap values in the first place.

Change your line 17 in the code to
 
attdmap = new Map<Student__c, Boolean>();

Also, its not a best practice to use the SObject as the Key. that is not really a way to do it, maybe you can using a map of Id and Sobject.

Something like
Map<Id,Student__c>




 

All Answers

logontokartiklogontokartik
The key you are loading is Student__c Object type, do you want to load the Id or the name instead?  you can try using attdkey.Name or attdkey.Id on line 04 instead
Vijay Kumar Rebbala 11Vijay Kumar Rebbala 11
@ogontokartik Thanks for your reply. But still there is no values displayed.
logontokartiklogontokartik
Sorry what did you use in your code? And what exactly are you trying to achieve?
Vijay Kumar Rebbala 11Vijay Kumar Rebbala 11
I have inserted data ionto map and i wanted to show those values on VFP.

Here is the debug log,

 
35.0 APEX_CODE,DEBUG;APEX_PROFILING,DEBUG;CALLOUT,DEBUG;DB,DEBUG;SYSTEM,DEBUG;VALIDATION,DEBUG;VISUALFORCE,FINE;WORKFLOW,DEBUG
19:53:27.050 (50573710)|EXECUTION_STARTED
19:53:27.050 (50606174)|CODE_UNIT_STARTED|[EXTERNAL]|06661000000JiVP|VF: /apex/Testpage
19:53:27.052 (52249843)|CODE_UNIT_STARTED|[EXTERNAL]|01p61000001riCZ|Testctrl <init>
19:53:27.052 (52268447)|SYSTEM_MODE_ENTER|true
19:53:27.053 (53542918)|SOQL_EXECUTE_BEGIN|[11]|Aggregations:0|SELECT Id, Name FROM Student__c
19:53:27.056 (56802799)|SOQL_EXECUTE_END|[11]|Rows:11
19:53:27.057 (57132704)|USER_DEBUG|[13]|DEBUG|*********Count**************11
19:53:27.057 (57517175)|USER_DEBUG|[15]|DEBUG|*********atu23.Id**************a0061000001hL4lAAE
19:53:27.057 (57650171)|USER_DEBUG|[15]|DEBUG|*********atu23.Id**************a0061000001hL4gAAE
19:53:27.057 (57740077)|USER_DEBUG|[15]|DEBUG|*********atu23.Id**************a0061000001hL4vAAE
19:53:27.057 (57826906)|USER_DEBUG|[15]|DEBUG|*********atu23.Id**************a0061000001hL4bAAE
19:53:27.057 (57912694)|USER_DEBUG|[15]|DEBUG|*********atu23.Id**************a0061000002Ray6AAC
19:53:27.058 (58009113)|USER_DEBUG|[15]|DEBUG|*********atu23.Id**************a0061000001hFnyAAE
19:53:27.058 (58098238)|USER_DEBUG|[15]|DEBUG|*********atu23.Id**************a0061000001f9seAAA
19:53:27.058 (58182866)|USER_DEBUG|[15]|DEBUG|*********atu23.Id**************a0061000002RdgfAAC
19:53:27.058 (58267675)|USER_DEBUG|[15]|DEBUG|*********atu23.Id**************a0061000001f9t8AAA
19:53:27.058 (58352369)|USER_DEBUG|[15]|DEBUG|*********atu23.Id**************a0061000002Re5uAAC
19:53:27.058 (58437702)|USER_DEBUG|[15]|DEBUG|*********atu23.Id**************a0061000001f9xkAAA
19:53:27.058 (58653712)|USER_DEBUG|[19]|DEBUG|************maps*****************{Student__c:{Id=a0061000001f9xkAAA, Name=Sree Pavan}=false, Student__c:{Id=a0061000001f9t8AAA, Name=Venu Kumar}=false, Student__c:{Id=a0061000001f9seAAA, Name=Vijay Kumar}=false, Student__c:{Id=a0061000002Ray6AAC, Name=a0061000002Ray6}=false, Student__c:{Id=a0061000001hL4gAAE, Name=dgfthnjdtf}=false, Student__c:{Id=a0061000001hFnyAAE, Name=esrrysefd}=false, Student__c:{Id=a0061000002Re5uAAC, Name=fdfgdfssd}=false, Student__c:{Id=a0061000002RdgfAAC, Name=ghcfj}=false, Student__c:{Id=a0061000001hL4bAAE, Name=reghewt}=false, Student__c:{Id=a0061000001hL4lAAE, Name=rteshydret}=false, ...}
19:53:27.058 (58677982)|CODE_UNIT_FINISHED|Testctrl <init>
19:53:27.058 (58729084)|CODE_UNIT_STARTED|[EXTERNAL]|01p61000001riCZ|Testctrl get(attdmap)
19:53:27.058 (58739566)|SYSTEM_MODE_ENTER|true
19:53:27.058 (58754835)|CODE_UNIT_STARTED|[EXTERNAL]|01p61000001riCZ|attdmap
19:53:27.058 (58765666)|CODE_UNIT_FINISHED|attdmap
19:53:27.058 (58779963)|CODE_UNIT_FINISHED|Testctrl get(attdmap)
19:53:27.078 (78304924)|VF_SERIALIZE_VIEWSTATE_BEGIN|06661000000JiVP
19:53:27.079 (79612874)|VF_SERIALIZE_VIEWSTATE_END
19:53:27.097 (97405948)|CUMULATIVE_LIMIT_USAGE
19:53:27.097 (97405948)|LIMIT_USAGE_FOR_NS|(default)|
  Number of SOQL queries: 1 out of 100
  Number of query rows: 11 out of 50000
  Number of SOSL queries: 0 out of 20
  Number of DML statements: 0 out of 150
  Number of DML rows: 0 out of 10000
  Maximum CPU time: 0 out of 10000
  Maximum heap size: 0 out of 6000000
  Number of callouts: 0 out of 100
  Number of Email Invocations: 0 out of 10
  Number of future calls: 0 out of 50
  Number of queueable jobs added to the queue: 0 out of 50
  Number of Mobile Apex push calls: 0 out of 10

19:53:27.097 (97405948)|CUMULATIVE_LIMIT_USAGE_END

19:53:27.097 (97461245)|CODE_UNIT_FINISHED|VF: /apex/Testpage
19:53:27.098 (98369752)|EXECUTION_FINISHED

 
Vijay Kumar Rebbala 11Vijay Kumar Rebbala 11
Updated code: 

<apex:page controller="Testctrl">
    <apex:form >
    <apex:repeat value="{!attdmap}" var="attdkey" >
            <apex:OutputText value="{!attdkey.Name}"/>
            <apex:OutputText value="{!attdmap[attdkey]}"/>
       </apex:repeat>
    <apex:commandButton action="{!submit}" value="Submit"/>
    </apex:form>
</apex:page>
logontokartiklogontokartik
Well I see the problem now. You are not populating the attdmap values in the first place.

Change your line 17 in the code to
 
attdmap = new Map<Student__c, Boolean>();

Also, its not a best practice to use the SObject as the Key. that is not really a way to do it, maybe you can using a map of Id and Sobject.

Something like
Map<Id,Student__c>




 
This was selected as the best answer
Vijay Kumar Rebbala 11Vijay Kumar Rebbala 11
Thanks that worked