0

I am trying to add a button in the last column of every row in a pageBlockTable. Something like 'Create' that will use the row level data and create/update an sObject via a controller.

When I use

<apex:column ><apex:commandButton action="/{!obj.id}" value="View" id="view_this_object"/></apex:column>

it throws an error:

Error: <apex:commandButton> (under <apex:page>) must occur between <apex:form></apex:form> tags.

This post and this are back from 2011, and it seemed to have worked then. I tried commandLink and it doesn't work either. What am I missing?

Visualforce:

<apex:page Controller="My_Controller" sidebar="true" showHeader="true" title="Title">

    <apex:pageBlock id="Main_Block">

        <apex:pageBlockTable value="{!myObj}" var="b">

            <apex:column ><apex:facet name="header">Name</apex:facet><apex:outputLink value="/{!b.Id}" target="_blank">{!b.Name}</apex:outputLink></apex:column> 
            <apex:column ><apex:facet name="header">Address</apex:facet><apex:outputText value="{!b.Address}"/></apex:column>
            <!-- ERROR BEGIN -->
            <apex:column ><apex:commandButton action="/{!b.id}" value="View" id="view_this_object"/></apex:column>
            <!-- ERROR END -->
        </apex:pageBlockTable> 

    </apex:pageBlock> 

</apex:page>

1 Answer 1

0

The error is self-explained, you have to use <apex:form for building your page. The reason why this was working in the old examples and didn't work for you is the fact that Salesforce updated they API several times from the moment when these articles were wrote.

UPDATE

If I understood you correct you need a page like this:

enter image description here

I've created this page based on your code by adding <apex:form> tag to the page:

enter image description here

<apex:page standardController="Account" recordSetVar="accounts" sidebar="true" showHeader="true" title="Title">
  <apex:form>
    <apex:pageBlock id="Main_Block">

        <apex:pageBlockTable value="{!accounts}" var="b">

            <apex:column ><apex:facet name="header">Name</apex:facet><apex:outputLink value="/{!b.Id}" target="_blank">{!b.Name}</apex:outputLink></apex:column> 
            <apex:column ><apex:facet name="header">Address</apex:facet><apex:outputText value="{!b.Name}"/></apex:column>
            <!-- ERROR BEGIN -->
            <apex:column ><apex:commandButton action="/{!b.id}" value="View" id="view_this_object"/></apex:column>
            <!-- ERROR END -->
        </apex:pageBlockTable> 

    </apex:pageBlock> 
 </apex:form>
</apex:page>
6
  • I understand the error, and I am using an apex:page. I DON'T want a commandButton outside my pageBlockTable and before apex:page. I would like a commandButton (or something similar) for every row in a pageBlockTable. Any thoughts on that? Feb 21, 2015 at 22:02
  • @Kal please post a whole code Feb 21, 2015 at 22:03
  • @Kal please see update Feb 21, 2015 at 22:23
  • Omg! I feel so stupid. All this while I was confusing myself with apex:page when the error and you said apex:form. Darn! Thank you :) Feb 21, 2015 at 22:26
  • On a similar note: I added an input value to the table- apex:inputHidden value="{!b.id}" id="bid" How do I get this value in my controller? Feb 21, 2015 at 22:48

You must log in to answer this question.

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