3

I am trying to send the selected Id to the controller class from VF page and getting error inside the action function method :

Here I want to pass parameters to the controller

Error: may not be used within an iterable component. You can use to define parameters for the function and pass iteration-specific values via the parameters.

 <apex:repeat value="{!Records}" var="item" >
        //.................
        //..................
   <apex:pageBlock mode="edit " id="pb">

      <apex:actionFunction action="{!deleteRecord}" name="deleteBtn" reRender="pb" >
        <apex:param name="selectedId" value="" assignTo="{!deleteId}"/>
        </apex:actionFunction>
        //.................
        //..................
   </apex:pageBlock>
</apex:repeat>

Apex:

public String deleteId { get; set; }
public void deleteRecord()
{
  system.debug('deleteId' + deleteId); 
}
5

You need to move your action function outside your iteration block and call it via Javascript by passing the parameter.

So before your iteration put this:

 <apex:actionFunction action="{!deleteRecord}" name="deleteThisRecord" rerender="pb">
    <apex:param name="selectedId" value="" assignTo="{!deleteId}" />
</apex:actionFunction>

And then inside your apex:repeat replace your current action function with:

<a onclick="if(confirm('You are about to delete this record')) deleteThisRecord('{!item.Id}');">Delete</a>
  • 1
    Hey! Referencing this for a VERY similar use case, only instead of Delete, my apex function is just selecting, but it's the exact same structure, just debugging...very reassuring that it's so similar, but it's not quite working for me. I have the apex:function called "itemSelectFunction" and pass it '{!item.ID}' in my repeat element. It ends up calling my controller function from the action in the apex:function but the value is null. Would you be able to help me out? Old topic, but it's SO similar I'm sure I've very close... – Natalie Spatharakis Mar 28 at 17:31
  • <a onclick="itemSelectFunction('{!item.Id}');">Select Item</a> and before the repeat elements I have <apex:actionFunction action="{!selectItem}" name="itemSelectFunction"> <apex:param name="selectedID" assignto="{!selectedItem}" value=""/> </apex:actionFunction> with "!selectItem" being in the controller and assignTo setting to a {get;set} in controller. – Natalie Spatharakis Mar 28 at 17:33
3

Why is your actionFunction inside of a repeater?

Think about the way AF's work. They are Javascript functions... And you wouldn't create the same function n times.

Instead, put the function outside the <apex:repeat> and call it the way you'd call a JS function. For Example: onclick="deleteBtn('{!someVariable}')".

Alternatively, if you wish, you can try to do the same thing with a button (inside of the repeater).

<apex:commandButton action="{!deleteBtn}" value="Delete" rerender="pb">
   <apex:param value="{!someVariable}" assignTo="{!deleteId}" />
</apex:commandButton>
  • Think about this scenario where we need to rerender one output panel when there are many output panels in the page, which gets dynamically generated and the Ids of those output panels have been made dynamic. Then how to pass dynamic rerender id? – Nagendra K S Mar 7 at 17:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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