You need to sign in to do that
Don't have an account?
Rafael.Martins.Santos
How show in the visualpage the value of an variable?
Hi All,
I'm trying create a visualpage that show the total amount of all opportunities closed.
In apex I did, but I don't know how I could display the results in visualpage.
My Apex code and visual page are like this:
APEX Code:
public class SumTotal {
public Double SumOpportunities(){
List<Opportunity> op = new List<Opportunity>();
op = [SELECT Id, Name, Amount, StageName FROM Opportunity WHERE Amount > 0 AND StageName ='Fechado e ganho'];
Double sum = 0.00;
for(Opportunity opty : op){
sum = sum + opty.Amount;
System.debug(' Name : '+opty.Name+', Sum: '+soma + ', Opty Amount: '+opty.Amount);
}
return sum;
System.debug('Sum: '+sum);
}
}
VisualPage:
<apex:page showHeader="false" sidebar="false" standardStylesheets="false"
applyHtmlTag="false" applyBodyTag="false" docType="html-5.0" controller="SumTotal">
<html>
<head>
<meta charset="utf-8"></meta>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"></meta>
<title>Teste</title>
<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"/>
</head>
<body>
<div class="container">
<div class="jumbotron">
<apex:dataTable value="{!Here I don't know what put}" var="sum">
<apex:column>
<apex:facet name="header">Product</apex:facet>
<apex:outputText value="{!Here I must display the results of the variable}" />
</apex:column>
</apex:dataTable>
</div>
Thanks
Rafael
</div>
</body>
</html>
</apex:page>
I'm trying create a visualpage that show the total amount of all opportunities closed.
In apex I did, but I don't know how I could display the results in visualpage.
My Apex code and visual page are like this:
APEX Code:
public class SumTotal {
public Double SumOpportunities(){
List<Opportunity> op = new List<Opportunity>();
op = [SELECT Id, Name, Amount, StageName FROM Opportunity WHERE Amount > 0 AND StageName ='Fechado e ganho'];
Double sum = 0.00;
for(Opportunity opty : op){
sum = sum + opty.Amount;
System.debug(' Name : '+opty.Name+', Sum: '+soma + ', Opty Amount: '+opty.Amount);
}
return sum;
System.debug('Sum: '+sum);
}
}
VisualPage:
<apex:page showHeader="false" sidebar="false" standardStylesheets="false"
applyHtmlTag="false" applyBodyTag="false" docType="html-5.0" controller="SumTotal">
<html>
<head>
<meta charset="utf-8"></meta>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"></meta>
<title>Teste</title>
<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"/>
</head>
<body>
<div class="container">
<div class="jumbotron">
<apex:dataTable value="{!Here I don't know what put}" var="sum">
<apex:column>
<apex:facet name="header">Product</apex:facet>
<apex:outputText value="{!Here I must display the results of the variable}" />
</apex:column>
</apex:dataTable>
</div>
Thanks
Rafael
</div>
</body>
</html>
</apex:page>
Please refer the below page.Let us know if this works.
All Answers
Use below upated code.
Class:
Visualforce page:
Hope this will helps you. mark it solved if its work for you.
Thanks
karthik
Please refer the below page.Let us know if this works.
Thanks for the help, it works.
But I don't understand one thing.
This line 13: "{!SumOpportunities}" var="s"
and this line 23 : value="${!sum}"
I see you not refer the "SumOpportunities" and the "sum" in the Apex code, and only add it to the visualpage.
How the visualpage understand that have to bring the results from apex (I know the relationship is connected by controller).
I have a difficult to understand how it works.
Can you explain to me please?
Thanks again
Rafael
I refered those variables in my visualforce page.In line 13 I have used "{!SumOpportunities}" to refer the method SumOpportunities which is returning the list of opportunity records and for line 23 I have used "${!sum}" to show the total amount using the variable sum from the code.'$' just used as prefix to show the amount in USD.You can achieve this using apex properities .To know more about it please follow the below link.
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_properties.htm
Please mark this question as solved if this solved your problem.
So the "SumOpportunities" is the method that you called as "getSumOpportunities()", is that right?
Because this is hard to understand. To me, in the "{!SumOpportunities}" should be {!getSumOpportunities}.
I don't know if your link that you shared with me, explian that, but I will take a look.
If you have more documents that will help me to comprehend that can you send to me?
Thanks again for your help.
Rafael
Please follow the link I shared with you,You will come to know.You can search for the resources like how you can display controller variables and methods in visualforce .You can take help from trailhead excercises.Thanks!!!.