0

I'm getting below error when I'm trying to pass values from map to pageblocktable in Visualforce page.

ERROR : Incorrect parameter type for subscript. Expected Number, received Text

VF PAGE :

<apex:pageBlockTable id="thetable" title="Invoice line item" value="{!Invoiceitemsmap}" var="inv" >

                        <apex:column headerValue="Nicomatic Part No"><apex:inputtext value="{!Invoiceitemsmap[Inv].Name}" required="true" /></apex:column>  

</apex:pageBlockTable> 

APEX CODE:

Public Map<Integer,List<Invoice_line_item__c >> Invoiceitemsmap{get;set;}
            contactList = [Select Name,Client_Part_No__c from Invoice where Id =:"SomeId"];
            totalCount = contactList.size();
            Invoiceitemsmap=new Map<Integer,List<Invoice_line_item__c>>();
            Invoiceitemsmap.put(totalCount,contactList);
            System.debug(Invoiceitemsmap);
  • 1
    Invoiceitemsmap[Inv] would give you a List<Invoice_line_item__c >, you would have to rewrite your code with use of wrapper classes to make code simpler. – Raul May 29 '19 at 12:51
  • You mean I need to write wrapper class and pass that wrapper list to there then it will also be the same right it is also a list only – vinodkumar May 29 '19 at 12:53
2

You are getting that error because, you are trying to use the dot notation on list variable on visualforce page.

As your Map structure is Map<Integer,List<Invoice_line_item__c>>,you will have to use two PageBlockTable's in order to display your Map in visualforce page, in first iteration of PageBlockTable, it will return you List<Invoice_line_item__c> and you cannot access the individual field's value i.e. Name from list without using the index. So in order to display this List again, you will have to use one more PageBlockTable.

Your visualforce page should be something like this

<apex:pageBlockTable id="thetable" title="Invoice line item" value="{!Invoiceitemsmap}" var="inv" >
    <apex:column >
        <apex:pageblocktable value="{!Invoiceitemsmap[Inv]}" var="inv1">
            <apex:column headerValue="Nicomatic Part No"><apex:inputtext value="{!inv1.Name}" required="true" /></apex:column>
        </apex:pageblocktable>
    </apex:column>
</apex:pageBlockTable> 

Not the answer you're looking for? Browse other questions tagged or ask your own question.