function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
john.krjohn.kr 

There needs to be a Total that adds up all the invoice line items

In that one i am creating a Invoice pdf vf page in the page i want total amount of invoice line items.how to write for loop and this total amount value how to insert vf page what commponet is used.please give me reply

Navatar_DbSupNavatar_DbSup

Hi,

You can use the following code for the reference in your Apex class of the VF page

 

list<invoice> invoiclist=[select amount from invoice];
integer sum=0;
if(invoiclist.size()>0)
{
for(invoice inv:invoiclist)
{
if(inv.amount!=null)
{
sum=sum+inv.amount;
}
}
}

 

Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved. 

 

john.krjohn.kr

How to add this list information in visualforce page? which component is used

Navatar_DbSupNavatar_DbSup

Hi,

 

Hi,

If you want to display the list information on the page you can either <apex:pageblocktable> or<apex:repeat>

Example of <Apex:pageblocktable>

 

<apex:pageBlockTable value="{!invoiclist}" var="invoiclistobj">

 <apex:column ><apex:facet name="header">Amount</apex:facet> {!invoiclistobj.amount}</apex:Column>

 

 </apex:pageBlockTable>

  </apex:pageBlock>

 

 

You can print the value of “sum property using the <apex:outputtext> on VF page

 

For example

 

<apex:outputText value="{!sum}"></apex:outputText>

 

Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved. 

john.krjohn.kr

I am trying to calculate Total amount (Total_Price_Amount__c).but it's not working-

aballardaballard

Take a look at summary formula fields which you could use to create a total field on the invoice object.  Then you wouldn't need any apex code....