This is a follow-up question to: When attempting to use a Map I get "System.NullPointerException: Attempt to de-reference a null object"

I am now receiving "Return type of an Apex action method must be a PageReference. Found: core.apexpages.el.adapters.ApexMapELAdapter " when trying to return a Map value with a Integer and custom object to a Visualforce Page.

Visualforce Page:

<apex:page standardController="Opportunity_Package__c" extensions="MetadataPackageEditor" action="{!getPackageMap}">
  <apex:form >
      <apex:inputField value="{!Opportunity_Package__c.Opp_Package_Rel__c}" id="Opporunity"/>
      <apex:pageBlock title="Select Package(s)">
      <apex:pageMessages />
      <span>Name </span>
      <apex:inputField value="{!Opportunity_Package__c.Name}"/>

      <table style="width:100%;">
                  <th>PPU Discount</th>
                  <th>Expiration Date</th>

              <apex:repeat value="{!packageMap}" var="oppPackage">
                  <td><apex:inputField value="{!packageMap[oppPackage].Name}" /></td>
                  <td><apex:inputField value="{!packageMap[oppPackage].Products__c}" /></td>
                  <td><apex:inputField value="{!packageMap[oppPackage].PPU_Discount__c}" /></td>


Code causing the issue:

Map<Integer, Package__c> packageMap { get; set; }

public Map<Integer, Package__c> getPackageMap() {

    Integer i = 0;

    packageMap = new Map<Integer, Package__c>();

    for (Package__c pack : [SELECT Name, Products__c, PPU_Discount__c FROM Package__c]) {
        packageMap.put(i, pack);

    return packageMap;


Opportunity Package is a junction record between Opportunity, and my custom object Package. Package is pulled via lookup, and then queried for it's detailed information.

1 Answer 1


On line 1, you have an action set to {!getPackageMap}. An action function must return "void" or "null" (no value), or a valid PageReference. It cannot return any other data type, or you'll get an error message.

Since you're actually calling that function from apex:repeat, there's no reason why you need to call the action method. You should remove it from your markup on line 1.

<apex:page standardController="Opportunity_Package__c" extensions="MetadataPackageEditor" <!-- action="{!getPackageMap}" --> >
  • You just fixed my issue. Thank you very much. The issue was a two part one! Part 1: I am not a smart man. Part 2: Not removing old usages of the method. Feb 23, 2015 at 18:47
  • Nah. It's an easy mistake to make. You'll get experience with coding, and you'll get better with time.
    – sfdcfox
    Feb 23, 2015 at 18:49

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .