1

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>
3
  • 2
    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. Commented Jun 3, 2014 at 21:58
  • Thank you for that information Daniel. It sounds like any examples using recordsetvar will not work for my requirements? Would you be able to tell me what I need to change to put me in the right direction? Once I can get a snippet that starts working I can start playing with it from there.
    – Ryan T
    Commented Jun 4, 2014 at 12:58
  • Obviously I don't know enough of what I'm doing. I editted my above post to include what I've tried to 'modify' to make it work, but don't understand the reason behind the error. Please see above. Any help would be appreciated.
    – Ryan T
    Commented Jun 4, 2014 at 13:35

2 Answers 2

1

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>
2
  • Hi Daniel, Thank you for this. I've read through your linked article which was very helpful. One thing though, When I use that code above for testing, it doesn't seem to create a field for data entry ,and when clicking save it loads the salesforce page within the visualforce page. I also added an 'edit' button but that does the same thing; loads the account page within the vf page.
    – Ryan T
    Commented Jun 5, 2014 at 18:40
  • I think I may abandon trying to make it edittable, and more just focus on trying to lay out columns and rows now that I understand the __c portion. I tried with pageblocktable but am having no luck getting things displayed, although the vf page saves without errors (added it to my main question at the bottom) - any help would be appreciated.
    – Ryan T
    Commented Jun 5, 2014 at 19:22
0

After much further research on what I was doing wrong, (and with the initial help of Daniel to figure out what I was missing with __c ) I figured out that the custom fields just won't render in a visualforce page on my edition of salesforce, without the fields themselves being present in page layout first. (that, to me, is redundant and not at all what I'm looking for) So I took a different approach.

As we do not have sales data in there as of yet, I created 12 fields under Opportunities, and put them on the page layout in there, and then named each opportunity under an account, the year of the sales data i'm inputting.

here is my code,

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

  <apex:pageBlockTable Columns="14" value="{!Account.Opportunities}" var="opp">

    <apex:column headerValue="Year" value="{!opp.Name}"/>
    <apex:column headerValue="Jan" value="{!opp.Jan__c}"/>
    <apex:column headerValue="Feb" value="{!opp.Feb__c}"/>
    <apex:column headerValue="Mar" value="{!opp.Mar__c}"/>
    <apex:column headerValue="Apr" value="{!opp.Apr__c}"/>
    <apex:column headerValue="May" value="{!opp.May__c}"/>
    <apex:column headerValue="Jun" value="{!opp.Jun__c}"/>
    <apex:column headerValue="Jul" value="{!opp.Jul__c}"/>
    <apex:column headerValue="Aug" value="{!opp.Aug__c}"/>
    <apex:column headerValue="Sep" value="{!opp.Sep__c}"/>
    <apex:column headerValue="Oct" value="{!opp.Oct__c}"/>
    <apex:column headerValue="Nov" value="{!opp.Nov__c}"/>
    <apex:column headerValue="Dec" value="{!opp.Dec__c}"/>
    <apex:column headerValue="Total" value="{!opp.Sum__c}"/>

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

Name is the 'year' that these sales are being reported for. Sum is a formula field adding up the 12 month fields.

Each year that is entered as an 'opportunity' under an account will automatically be shown in this table as a new row.

The only issue i've ran into now is how to control the order in which they appear.

You must log in to answer this question.

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