I am trying to create a table in VisualForce that has both filters for the X and Y axis. Is this possible? For example: accountId 12345 has both tasks and notes. I want to be able to view both tasks and notes for this account in the same table. Thank you! Table data for one account id

  • Can you explain in more depth the data structure? Are you always going to have the same number of notes and tasks? – Adrian Larson Jul 12 '16 at 17:08
  • No, there is no limit on the amount of tasks or notes. I want the table to auto populate with all of the accounts tasks or notes that were created. So there could be 1 or there could be 100. – Olivia Jul 12 '16 at 17:11
  • But you want to strictly alternate them? Why not just do two separate tables? All notes first, then all tasks. Seems much simpler to implement. – Adrian Larson Jul 12 '16 at 17:18
  • We actually already have the functionality of two different tables. But management would like to see both tasks and notes all in one table and they want them to be listed under one another. My guess is they want it this way for ease of viewing. Do you think it would be possible to do this customization? – Olivia Jul 12 '16 at 17:23
  • 1
    It can be accomplished, but a lot is left up to the imagination in your currently stated requirements. How do you figure out which Task to layer under which Note? What happens if you have more notes than tasks or vice versa? – Adrian Larson Jul 12 '16 at 17:39

Just use a List<SObject> property. Your controller should look something like:

public with sharing class MyController
    public List<SObject> tasksAndNotes { get; private set; }
    public MyController()
        tasksAndNotes = new List<SObject>();
        tasksAndNotes.addAll([SELECT ... FROM Task WHERE ...]);
        tasksAndNotes.addAll([SELECT ... FROM Note WHERE ...]);

You can use a more sophisticated strategy to layer them in if you want.

Your markup would then look something like the below (002 is the key prefix for Note).

<apex:pageBlockTable value="{!tasksAndNotes}" var="record">
    <apex:column headerValue="Title/Subject">
        <apex:variable var="field" value="{!IF(BEGINS(record.Id, '002'), 'Title', 'Subject')}" />
        <apex:outputField value="{!record[field]}" />
    <apex:column headerValue="Body/Comment">
        <apex:variable var="field" value="{!IF(BEGINS(record.Id, '002'), 'Body', 'Description')}" />
        <apex:outputField value="{!record[field]}" />
    <apex:column headerValue="Created Date">
        <apex:outputField value="{!record['CreatedDate']}" />
    <apex:column headerValue="Created By">
        <apex:outputField value="{!record['CreatedById']}" />
  • Thank you for this. I understand the visualforce code but the APEX code is still fuzzy to me. Can you explain a little more about what is needed with this? I believe that I have to define tasks and notes first from a query, as well as make them in a public scope. Am I close? When I do this I get two errors: " 'Unknown property 'TaskAndNote.tasksAndNotes'.'" and "Didn't understand relationship 'Note' in FROM part of query call. " – Olivia Jul 13 '16 at 15:32
  • @Olivia I added an example of what your controller should look like. – Adrian Larson Jul 13 '16 at 21:45
  • Took me a little but I got it! Thank you for the guidance. – Olivia Jul 14 '16 at 21:52

Although I like Larson's answer above, I think it is better to organize the data in the Apex layer, and minimize the logic in the presentation/VF layer.

In this case, you could make a custom object (not an "S" object) in apex that has the data exactly as you want it, with the interleaved rows. Then deliver the data to PageBlockTable... no variable tags would be needed, and you'd be manipulating the data with a more powerful language (apex).

here are links on wrapper objects specifically for the purpose of delivering additional columns (a checkbox) or additional rows (account child records) to Visual Force pages:



  • 1
    I imagine you will see some view state bloat by adopting this approach. – Adrian Larson Jul 12 '16 at 18:36
  • 1
    not sure where the additional bulk would come from. I added links to clarify what I was describing. – SeanW Jul 12 '16 at 20:06
  • If you include which columns to display in the wrapper, that's additional view state. – Adrian Larson Jul 13 '16 at 13:10
  • For this problem, the wrapper should always only include 4 columns. Their technical names could be 'string1', 'string2', 'date1', and 'string3'. It doesn't matter. Apex would fill in the right values from the Task or Note. Apex should sequence them correctly also. Then VF just rolls through the records, and applies layout. – SeanW Jul 13 '16 at 20:00

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.