+ Start a Discussion
forawormforaworm 

Reports with Apex

Hi all,

 

We lend Demo-Products to our customers by a certain time period with a lot of date fields.

(delivery date to customer, arrival date at customer, delivery date back to us, arrival date back to us, ...)

 

I need a report that gives a overview over all Demo-Products, which shows where is a Product at certain point of time.

I can not present it in a well readable presentation with Salesforce standard tools.

 

Is there any possibility to create reports with Apex or extend Salesforce customized reports with Apex.

 

Thanks!

WesNolte__cWesNolte__c

Hey

 

If your dataset isn't too big you can use apex, SOQL, and Visualforce pages, rendered as PDFs to create spiffy reports. Check out the 'renderAs' attribute of <apex:page> within the component reference.

 

Cheers,

Wes

forawormforaworm

I am new in Salesforce and Apex.

Do you hava a short example for me?

Only to read some Opportunities and display them in a tabular form.

Maybe a short code example and how to integrage it in Salesforce.

A click on a button should show the result. 

 

Thanks! 

prageethprageeth

Hello 

Following is an simple example. You need one controller class and two Visualforce pages.

Note that words marked with the same color have some relationships. 

 

Your controller: 

 

public class MyClass{

public Opportunity[] getOpportunityList() {

Opportunity[] opps = [SELECT

name,

account.name,

amount,

owner.name

FROM

Opportunity

LIMIT 5

];

return opps;

}

 

public pageReference generateReport() {

return Page.secondPage;

}

} 

 

Your fist page:(the button is in this page.) 

 

<apex:page controller="MyClass">

<apex:form>

<apex:commandButton value="Generate Report" action="{!generateReport}"/>

</apex:form>

</apex:page>

 

 

 Your second page:(this is the report.Name this page as "secondPage"

 

<apex:page renderAs="pdf" Controller="MyClass">

<apex:datatable value="{!opportunityList}" var="opp" columnsWidth="25%,25%,25%,25%">

<apex:column value="{!opp.name}" headerValue="Name"/>

<apex:column value="{!opp.amount}" headerValue="Name"/>

<apex:column value="{!opp.account.name}" headerValue="Account Name"/>

<apex:column value="{!opp.owner.name}" headerValue="Owners Name"/>

</apex:datatable>

</apex:page>

 

 

 

 

Krishna1317Krishna1317

Hi Weznolte,

 

I have a large dataset. How to do reports for that?

Amator_VitaeAmator_Vitae

Set the readOnly attribute for the Visualforce page to TRUE;

 

e.g.

 

<apex:page controller="myCustomController" readOnly="true" renderAs="pdf" sidebar="false" showHeaders="false">

 

From http://www.salesforce.com/us/developer/docs/pages/Content/pages_compref_page.htm:

readOnly:

 

A Boolean value that enables read-only mode for a Visualforce page. In read-only mode, a page may not execute any DML operations, but the limit on the number of records retrieved is relaxed from 50,000 to 1 million rows. It also increases the number of items in a collection that can be handled by iteration components, from 1,000 to 10,000. If not specified, this value defaults to false.