[SalesForce] Trying to create a table (edittable or not) with visualforce from fields that exist within account

I am trying to create a visualforce page to be displayed within accounts that ideally will be edittable (but if this isn't possible, then just a table to display the fields' values) that lays out a number of fields in columns and rows.

I've tried taking some code that I've found and I'm having a lot of trouble with all of it.
I am on professional edition salesforce, and so I have to use only standard controllers.

One example I found, when I save this as a VF page it doesn't show up in page layout under accounts. I have no idea why though, as I'm using the standard account controller? The below example is unchanged from how I found it:

    <apex:page standardController="Account" recordSetVar="accounts" 
    tabstyle="account" sidebar="false">
       <apex:form> 
       <apex:pageBlock >
       <apex:pageMessages />
       <apex:pageBlockButtons>
          <apex:commandButton value="Save" action="{!save}"/>
       </apex:pageBlockButtons>

       <apex:pageBlockTable value="{!accounts}" var="a">
          <apex:column value="{!a.name}"/>

          <apex:column headerValue="Industry">
     <apex:inputField value="{!a.Industry}"/>
          </apex:column>

       </apex:pageBlockTable>
       </apex:pageBlock>
       </apex:form>
    </apex:page>

For testing, I've created Jan to Dec as separate 'number' fields (12 character, 2 decimal) uniquely named Jan2014 to Dec2014 – I don't know if this is the right way to go about it. I've also tried creating a fieldset with all 12 of those fields in one set, and then attempted to use some examples I've found on using fieldsets, but was not successful.

I've found How to display FieldSet label and its value in PageBlockTable – but cannot figure out how to modify it to how I need (and any variation I have tried I can't get to show up in page layout under accounts, even though I'm using the account standard controller)

(As I can't get the vanilla example to show up in page layout it doesn't matter yet, but I've tried putting in !a.Jan2014 – is this the right syntax to access this number field i've created within accounts, using the above example of variables and values?

I'd like to lay them out horizontally in a row (for 2014, and then a 2nd row for 2013, etc), but I can't even get the vanilla example to show up in page layout.

— what i'd like to do is display 12 records (jan to dec) in a row, representing present year (2014), then a 2nd row for 2013, 12 records.. and so on.

I tried laying out 3 in a row as a test, and the vf page saved but this doesn't render anything but a thin grey rectangle with a horizontal line in the middle, as a VF page:

<apex:page standardController="Account" sidebar="false">
   <apex:pageBlock>
      <apex:pageBlockTable Columns="12" value="{!Account}" var="Acc">
         <apex:column headerValue="Jan" value="{!Acc.Jan2014__c}"/>
         <apex:column headerValue="Feb" value="{!Acc.Feb2014__c}"/>
         <apex:column headerValue="Mar" value="{!Acc.Mar2014__c}"/>
      </apex:pageBlockTable>
   </apex:pageBlock>
</apex:page>

I can already foresee an issue once I get to the 2nd line , if 'headervalue' has a title for those entries on the next 'row' which I don't want. but right now, I can't even get my test to render…

Can someone please explain to me why this works:

 <apex:page standardController="Account" sidebar="false">
 <apex:form >
 <apex:pageBlock >
   <apex:pageBlockTable Columns="12" value="{!Account}" var="acc">
  <apex:column value="{!acc.name}" headerValue="Jan"/>
 </apex:pageBlockTable>
 </apex:pageBlock>
 </apex:form>
 </apex:page>

but changing !acc.name to !acc.Jan2014__c displays nothing? (neither the 'Jan' header, nor the data stored for the field for that particular account)… what am I missing?!!
For Jan2014__c it should show '25' as that's the amount I have stored in that field for this account. Yet it just renders a wide rectangle with no text when I do that.

I've also tried:

<apex:page standardController="Account" sidebar="false">
<apex:form >
<apex:pageBlock >
  <apex:pageBlockTable Columns="12" value="{!Account}" var="acc">
  <apex:column >
  <apex:facet name="header">Jan</apex:facet>
  <apex:outputText value="{!acc.Jan2014__c}" />
  </apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>

Best Answer

As per your original question and my comment:

Your example VF page doesn't show up under the Account page layouts as the recordSetVar attribute indicates it is a "set-oriented standard controller". You can use this to override the List, Accounts Tab, and custom list buttons. Not the New/View/Edit/Delete buttons. You are working with multiple records, not a single record.


Your custom fields will need the __c suffix when working from Visualforce. This is the API name for the field.

See Building Visualforce Pages Using Standard Controllers - Referencing a Single Record:

<apex:page standardController="Account" sidebar="false">

    <apex:pageMessages />

    <apex:form> 
        <apex:pageBlock>
            <apex:pageBlockButtons>
                <apex:commandButton value="Save" action="{!save}"/>
            </apex:pageBlockButtons>

            <apex:pageBlockSection title="Details">
                <apex:pageBlockSectionItem>
                    <apex:outputLabel value="Jan 2014"/>
                    <apex:inputField value="{!Account.Jan2014__c}"/>
                </apex:pageBlockSectionItem>
            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
</apex:page>
Related Topic