My Data displays the list results as grouped but does not create a singular display for the same value.
I would like the returned Data to Show everything grouped into a single column header...let me share the code.
To elaborate :
public Summary[] Summaries { get; set; }
public Alphabet() {
AggregateResult[] groupedResults = [select A,Sum(B)Currency,C from D WHERE A != null AND C < LAST_FISCAL_QUARTER GROUP BY A,C ORDER BY A limit 1000];
Summaries = new List<Summary>();
for (AggregateResult ar : groupedResults) {
Summaries.add(new Summary(ar));
}
}
public class Summary {
public String A{ get; private set; }
public Decimal B{ get; private set; }
public Date C{ get; private set; }
public Summary(AggregateResult ar) {
A= (String) ar.get('A');
B= (Decimal) ar.get('B');
C= (Date) ar.get('C');
}
}
}
My Page :
<apex:page controller="Alphabet">
<apex:form >
<apex:pageBlock >
<apex:pageBlockTable value="{! Summaries}" var="s">
<apex:column value="{! s.A}"/>
<apex:column value="{! s.B}"/>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>
My Display :
enter image description here
But I would like it to look like this :
enter image description here
I deally I would like all th A1 values summed up together and not showing multiple A1's.
Please assist.
Related
Roles are assigned to each Employee and each employee has a checkbox. Whenever checkbox is checked and Role selected from Dropdown(Roles from Picklist), New Role Should be assigned to Employee after clicking on Update Button.
How do i get it.. I've assigned ID to checkbox and trying like if Checkbox==true then perform certain condition but it is not working..Please guide me
VF Page
<apex:page extensions="EmployeeSelectClassController13" standardController="Employee__c" sidebar="false">
<apex:form >
<apex:pageBlock >
<apex:pageBlockSection title="Employees" collapsible="false">
<apex:pageBlockTable value="{!wrapEmployeeList}" var="empWrap" id="table" title="All Employees">
<apex:column >
<apex:inputCheckbox value="{!empWrap.selected}" id="inputCheckbox"/>
</apex:column>
<apex:column value="{!empWrap.emp.Name}" id="inputName" />
<apex:column value="{!empWrap.emp.Role__c}" id="inputRole" />
</apex:pageBlockTable>
<apex:pageBlockSection id="InfoId" columns="1" >
<apex:selectList size="1" value="{!SelectedValue}">
<apex:selectOptions value="{!statusOptions}"/>
</apex:selectList>
</apex:pageBlockSection>
<apex:commandButton value="Update" id="inputButton" action="{!updateRole}" />
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
Apex Controller
public class EmployeeSelectClassController13 {
public List<wrapEmployee> wrapEmployeeList {get; set;}
public List<Employee__c> empRecord {get;set;}
public string selectedValue { get;set; }
public List<SelectOption> statusOptions { get;set; }//TO get Roles from Employee
public EmployeeSelectClassController13(ApexPages.StandardController controller){
if(wrapEmployeeList == null){
wrapEmployeeList = new List<wrapEmployee>();
for(Employee__c empList:[Select Name,Role__c from Employee__c]){
wrapEmployeeList.add(new wrapEmployee(empList));
autorun();
}
}
}
public class wrapEmployee{
public Employee__c emp {get; set;}
public Boolean selected {get; set;}
public wrapEmployee(Employee__c e) {
emp = e;
selected = false;
}
}
//To get all Roles(PickList) from Employee Object
public void autoRun()
{
Schema.DescribeFieldResult statusFieldDescription = Employee__c.Role__c.getDescribe();
statusOptions = new list<SelectOption>();
for (Schema.Picklistentry picklistEntry : statusFieldDescription.getPicklistValues())
{
statusOptions.add(new SelectOption(pickListEntry.getValue(),pickListEntry.getLabel()));
}
}
public void updateRole()
{
}
}
Something like this? You don't need IDs in the Visualforce unless you do some JavaScript magic. This can be done completely in Apex.
public void updateRole(){
List<Employee__c> toUpdate = new List<Employee__c>();
for(wrapEmployee wrap : wrapEmployeeList){
if(wrap.selected){
wrap.emp.Role__c = SelectedValue;
// wrap.selected = false; // you could choose to untick checkboxes now?
// or after successful update loop through them one more time and then untick
toUpdate.add(wrap.emp);
}
}
update toUpdate;
}
Let's pretend that I have an sObject called MyCutomObject with the fields Column1, Column2, Column3, PickMeColumn and others. The type of the PickMeColumn is Picklist.
While it's easy to access the object's instance data in my page, I'm a bit stucked with how to get the user's input data from that page to be accessible inside the controller.
Page code:
<apex:page sidebar="false" standardController="MyCustomObject__c" extensions="MyCustomSearchController">
<apex:form >
<apex:pageBlock title="Search Criteria">
<apex:pageBlockSection>
<apex:inputField value="{!myObject.PickMeColumn__c}" />
</apex:pageBlockSection>
<apex:commandButton value="Search" id="SearchButton" action="{!search}"/>
</apex:pageBlock>
<apex:pageBlock title="Search Results">
<apex:pageBlockTable value="{!myObjectList}" var="myObject">
<apex:repeat value="{!myObject}" var="aRecord">
<apex:column value="{!aRecord.Column1__c}"/>
<apex:column value="{!aRecord.Column2__c}"/>
<apex:column value="{!aRecord.Column3__c}"/>
</apex:repeat>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>
Controller code:
public class MyCustomSearchController {
public MyCutomObject__c myObject {get;set;}
public List<MyCutomObject__c> myObjectList {get;set;}
public MyCustomSearchController(ApexPages.StandardController controller) {
}
public PageReference search() {
String ValueSelectedByUser = '??? Help!';
myObjectList = [SELECT Column1__c, Column2__c, Column3__c FROM MyCutomObject__c WHERE PickMeColumn__c = ValueSelectedByUser];
return ApexPages.currentPage();
}
}
In controller's code simply like so:
public class MyCustomSearchController {
public MyCutomObject__c myObject {get;set;}
public List<MyCutomObject__c> myObjectList {get;set;}
public MyCustomSearchController(ApexPages.StandardController controller) {
myObject = new myCustomObject__c(); // Must create the object!
}
public PageReference search() {
String ValueSelectedByUser = myObject.PickMeColumn__c;
myObjectList = [SELECT Column1__c, Column2__c, Column3__c FROM MyCutomObject__c WHERE PickMeColumn__c = :ValueSelectedByUser];
// Have to add the colon
return ApexPages.currentPage();
}
}
I want to list the Result of Survey From tables, but I am getting error
Unknown property 'String.Name'
I need to show the result on VisualForce page.
VF page
<apex:page showHeader="false" sidebar="false" controller="SurveyResultController">
<apex:form>
<apex:pageBlock title="Submited Result">
<apex:pageBlockTable value="{!SurveyResult}" var="sr">
<apex:column value="{!sr.Name}"/>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
Apex Controller
public with sharing class SurveyResultController {
public String surveyId {
get;
set{
this.surveyId = value;
}
}
public Integer SurveySessionID {
get;
set{
this.SurveySessionID = value;
}
}
public String ssessionid {
get;
set;
}
public SurveyResultController() {
surveyId = Apexpages.currentPage().getParameters().get('id');
ssessionid = Apexpages.currentPage().getParameters().get('ssessionid');
}
public List<String> getSurveyResult() {
List<tblSurveyResult__c> qr = [SELECT Name,
QuestionID__c,
SurveyID__c,
Answer__c,
QuestionID__r.Id,
QuestionID__r.Name,
QuestionID__r.Question__c,
QuestionID__r.SelectedAnswer__c
FROM tblSurveyResult__c
WHERE SurveyID__c = :surveyId
AND SurveySessionID__c = :SurveySessionID];
List<String> resp = new List<String>();
for (tblSurveyResult__c r : qr) {
resp.add(r.Name);
}
return resp;
}
}
in the following line
<apex:column value="{!sr.Name}"/>
you try to read Name from String entity.
In the controller you prepared a List<String> and return it to the page.
List<String> resp = new List<String>();
for (tblSurveyResult__c r : qr) {
resp.add(r.Name);
}
return resp;
So, your options:
Use the following format on the page
<apex:column value="{!sr}"/>
return list of tblSurveyResult__c to the page
public List<tblSurveyResult__c > getSurveyResult() {
return [SELECT Name,
QuestionID__c,
SurveyID__c,
Answer__c,
QuestionID__r.Id,
QuestionID__r.Name,
QuestionID__r.Question__c,
QuestionID__r.SelectedAnswer__c
FROM tblSurveyResult__c
WHERE SurveyID__c = :surveyId
AND SurveySessionID__c :SurveySessionID];
}
EDIT due to your comments please use the second option
Return list of tblSurveyResult__c to the page
public List<tblSurveyResult__c > getSurveyResult() {
return [SELECT Name,
QuestionID__c,
SurveyID__c,
Answer__c,
QuestionID__r.Id,
QuestionID__r.Name,
QuestionID__r.Question__c,
QuestionID__r.SelectedAnswer__c
FROM tblSurveyResult__c
WHERE SurveyID__c = :surveyId
AND SurveySessionID__c :SurveySessionID];
}
<apex:page showHeader="false" sidebar="false" controller="SurveyResultController">
<apex:form>
<apex:pageBlock title="Submited Result">
<apex:pageBlockTable value="{!SurveyResult}" var="sr">
<apex:column value="{!sr.SurveyID__c}"/>
<apex:column value="{!sr.Name}"/>
<apex:column value="{!sr.QuestionID__r.Question__c}"/>
<apex:column value="{!sr.QuestionID__r.SelectedAnswer__c}"/>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
I have a dynamic picklist field that contains all the apex classes name that are in my org. There is a "Show" button on the page as well. Now if a user selects a value from this picklist and clicks on Show button, the apex code of that class should get displayed below.
Pls suggest how can I implement it in my VF page.
Thanks!
<apex:form >
<apex:selectList value="{!selectedClass}" size="5">
<apex:selectOptions value="{!ClassList}" ></apex:selectOptions>
</apex:selectList>
<apex:pageBlock >
<apex:commandButton action="{!show}" value="Show" id="Button"/>
<apex:pageBlockSection title="My Current Class">
You could query the body field of the ApexClass object for what you're looking for:
public class SomeController {
private List<ApexClass> allApexClasses;
public String selectedClass {public get; public set;}
public String apexCodeOutput {public get; private set;}
public SomeController() {
// only select classes that aren't part of a managed package, since you won't be able to view the body
allApexClasses = [select id, name, body from ApexClass where lengthwithoutcomments <> -1 order by name asc];
}
public List<SelectOption> getClassList() {
List<SelectOption> opts = new List<SelectOption> opts;
for ( ApexClass ac : allApexClasses )
opts.add(new SelectOption(ac.Id, ac.Name));
return opts;
}
public PageReference show() {
if ( selectedClass != null ) {
Id classId = (Id) selectedClass;
for ( ApexClass ac : allApexClasses ) {
if ( classId == ac.Id ) {
apexCodeOutput = ac.body;
break;
}
}
}
return null;
}
}
And then in your VF page, just rerender the output code when clicking the button. You'll want to use a <pre> tag around the code to preserve spacing so the code is readable.
<apex:form>
<apex:selectList value="{!selectedClass}" size="5">
<apex:selectOptions value="{!ClassList}" ></apex:selectOptions>
</apex:selectList>
<apex:pageBlock >
<apex:commandButton action="{!show}" value="Show" rerender="apexoutput" id="Button"/>
<apex:pageBlockSection title="My Current Class">
<apex:outputPanel id="apexoutput">
<pre>{!apexcodeoutput}</pre>
</apex:outputPanel>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
I'm very new to Visualforce.
I'm looking at this page here: http://force.siddheshkabe.co.in/2010/11/displaying-aggregate-result-on.html
So when I added this code onto a VisualForce page:
AggregateResult[] groupedResults = [SELECT Name, Days__c FROM Contact WHERE Days__c != ];
for (AggregateResult ar : groupedResults) {
System.debug('Name: ' + ar.get('Name') + '\nDays Taken : ' + ar.get('Days__c') + '\n');
But all it does is print the code instead of executing it. What should I be doing? Thanks for any guidance.
The Apex code goes into a custom controller or controller extension. The VisualForce page is a separate file from the controller. The page you referenced doesn't show the VF page. Also, I don't think you can bind VF components to AggregateResult, so you'll need a wrapper class.
Here's some working code.
Controller:
public with sharing class TestController {
public Summary[] Summaries { get; set; }
public TestController() {
AggregateResult[] results = [
SELECT Name, Count(Id) Quantity FROM Opportunity GROUP BY Name
];
Summaries = new List<Summary>();
for (AggregateResult ar : results) {
Summaries.add(new Summary(ar));
}
}
// wrapper class to hold aggregate data
public class Summary {
public Integer Quantity { get; private set; }
public String Name { get; private set; }
public Summary(AggregateResult ar) {
Quantity = (Integer) ar.get('Quantity');
Name = (String) ar.get('Name');
}
}
}
VF page:
<apex:page controller="TestController">
<apex:form >
<apex:repeat value="{!Summaries}" var="summary">
{!summary.Name}: {!summary.Quantity}<br/>
</apex:repeat>
</apex:form>
</apex:page>