5

Can anyone please clarify the following technical questions regarding reporting.

•Can we create dynamic column header text in Reports? For example if we create a report that displays sales data for the current, previous and next month can we display the name of the month dynamically based on the current month.

•Is it possible to display multiple reports in a single page similar to dashboards? If not a standard feature how do we achieve this by visualforce?

3
  1. No. Headers are based on field names, and field names cannot be dynamic. You would need to update the field names (and their formulas) to be accurate.

  2. A dashboard is a collection of reports. Displaying detail data would be relatively unwieldy, but if you were determined to do this, you could achieve this in Visualforce. A very basic example follows:

Page:

<apex:page controller="reportViewer" readOnly="true">
    <apex:dataTable value="{!reports}" var="report">
        <apex:column value="{!report.name}" headerValue="Report Name"/>
        <apex:column headerValue="Results"><apex:outputText escape="false" value="{!report.data}"/></apex:column>
    </apex:dataTable>
</apex:page>

Controller:

public with sharing class reportViewer {
    public class ReportItem {
        public string name { get; set; }
        public string data { get; set; }
    }

    Report[] records;

    public reportViewer() {
        records = [select id,name from report limit 5];
    }

    public ReportItem[] getReports() {
        ReportItem[] results = new ReportItem[0];
        for(Record record:records) {
            ReportItem item = new ReportItem();
            item.name = record.name;
            item.data = new apexpages.pagereference('/'+record.id+'?excel=1').getContent().toString();
            results.add(item);
        }
        return results;
    }
}
  • Note, this code hasn't been tested beforehand, so it may require small adjustments.

  • For more complex scenarios, you'll have to parse the output from the report yourself, which may be non-trivial.

| improve this answer | |
  • Thank you for your reply. I have tried the Visualforce page for displaying reports in a single page. The output looks fine but I cannot click the record and go into the particular record as standard reports. Is there anyway to achieve this? – Arun Nov 4 '13 at 7:15
  • Using the output format I demonstrated should suffice; they should be standard links. If you're exporting as a CSV file, you have to generate the links yourself. – sfdcfox Nov 4 '13 at 7:18
0

Can we create dynamic column header text in Reports? For example if we create a report that displays sales data for the current, previous and next month can we display the name of the month dynamically based on the current month.

Answer

Page:

Controller:

public with sharing class Dynamicheader {

public String getFirstheader() 
{
       DateTime d = datetime.now();
  String monthName= d.format('MMMMM');
//System.debug(monthName);
    return String.valueof(monthName);
}


public String getSecondHeader() 
{
DateTime d = datetime.now().addMonths(1);
  String monthName= d.format('MMMMM');
//System.debug(monthName);
    return String.valueof(monthName);
}

public String getthirdHeader() 
{
DateTime d = datetime.now().addMonths(-1) ;
  String monthName= d.format('MMMMM');
//System.debug(monthName);
    return String.valueof(monthName);
}


List<Account> accountList= new List<Account>();

public List<Account> getAccounts()
{
    for(Account a: [select Id, Name, AccountNumber, Phone from Account limit 5])
    accountList.add(a);
    return accountList;
}

}

| improve this answer | |

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.