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
B2000B2000 

Error Saving VF Page Using a CommandLink Action Calling an Inner Class Method With a Map

I have an inner class that has a method I want to call using a Map.  I get the following error when trying to save the VF Page.  The CommandLink line of code is causing the error.

Error Error: java.lang.UnsupportedOperationException
Error Error: null

Here is the code:
public with sharing class TestInnerClass
{
  class wA
  {
 
public  Account         a    {get;set;}
public wA(Account a){this.a = a;}
public void saveAcc(){upsert a;}
 
  }
  public Map<String,wA> mapWAcc {get;set;}

  public TestOuterClass()
  {
  mapWAcc  = new Map<String,wA>(); 
  mapWAcc.put('Test',new wA(new Account(Name='Test')));
  }
}

<apex:page controller="TestOuterClass">
<apex:form >
    <apex:repeat value="{!mapWAcc}" var="idMap">
    <apex:repeat value="{!mapWAcc[idMap]}" var="wAcc">
        <apex:inputField value="{!wAcc.a.Name}"/>
        <apex:commandLink value="Save" action="{!wAcc.saveAcc}"/>
    </apex:repeat>
    </apex:repeat>
</apex:form>
</apex:page>

Thanks
crop1645v2crop1645v2
commandLink can't call arbitrary methods; the action= attribute must refer to a method with signature of an Action method - that is, no arguments and returns a PageReference

public PageReference myActionMethod() { ..}
B2000B2000
Thanks for your response.  Unfortunately, the issue is the Map as CommandLinks  or CommandButtons can execute void methods.  When I make the variable a list of the wrapper class it works correctly (code below works).  The VF page saves (which it will not do when it is a map).  When I execute the VF page and click the "Save" link, the record is upserted.

public with sharing class TestInnerClass
{
class wA
{
  public  Account         a    {get;set;}
  public wA(Account a)
  {
   this.a = a;
  } 
  public void saveAcc(){upsert a;}
 
}

public Map<String,wA> mapWAcc {get;set;}
public wA[] listWAcc   {get;set;}
public TestInnerClass()
{
  mapWAcc  = new Map<String,wA>();
  listWAcc = new wA[]{}; 
  mapWAcc.put('Test',new wA(new Account(Name='Test')));
  listWAcc.add(mapWAcc.get('Test'));
}
}

<apex:page controller="TestInnerClass">
<apex:form >
    <!--<apex:repeat value="{!mapWAcc}" var="idMap">-->
    <!--<apex:repeat value="{!mapWAcc[idMap]}" var="wAcc">-->
    <apex:repeat value="{!listWAcc}" var="wAcc">
        <apex:inputField value="{!wAcc.a.Name}"/>
        <apex:commandLink value="Save" action="{!wAcc.saveAcc}"/>
    </apex:repeat>
    <!--</apex:repeat>-->
</apex:form>
</apex:page>
crop1645v2crop1645v2
1. Yes, I've seen others do the public void myMethod() approach and it does seem to work but that is only because (I think), that a void method is treated the same as returning a null PageReference by VF

2. As for commandLinks within collections, I suggest you look at this http://bobbuzzard.blogspot.com/2011/07/passing-parameters-to-apex-method-from.html which describes a way to communicate to the controller which map key is being referenced by the commandLink
B2000B2000
Thanks again.  Bob as always has excellent posts.  Passing parameters back to an action method is extremely useful and I have used this technique for many years.  

I did find another post that addresses my issue of accessing an inner class's method thru a map and that it is a SF bug.  In my case I can't get the VF page to save.  In her case, she can save the VF page, but generates an error during execution (she was using an earlier VF release).  Here is the link: https://developer.salesforce.com/forums?id=906F000000098QNIAY
crop1645v2crop1645v2
B2000 - interesting ; I've never tried using inner class methods referenced by VF maps and now I know the workaround. Thanks