Salesforce Unknown property 'String.Name' - salesforce

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>

Related

Need to update Roles(Custom FIeld) of the Employee(Custom) those are Checked

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;
}

Page is not re-rendering after adding select list code

I am new In salesforce, currently learning a visualforce elements.
I am having a problem in my code that when I insert a SelectList code in my visualForce page then page re-rendering stops working.
Without SelectList page re-rendering works fine.
I have provided a code snippets below. After adding SelectList save method from controller not getting called also contact i am trying to insert is not getting inserted.
Any help is appreciated.
This is my visualforce page.
<apex:page controller="ContactController">
<apex:form >
<apex:pageBlock>
<apex:pageBlockSection >
<apex:inputField value="{!Contact.AccountId}" label="Account Name:"/>
<apex:inputField value="{!Contact.LastName}" label="LastName"/>
<apex:inputField value="{!Contact.phone}" label="Phone"/>
<apex:inputField value="{!Contact.Department}"/>
<apex:inputField value="{!Contact.Designation__c}"/>
</apex:pageBlockSection>
<apex:pageBlockSection id="id3">
<apex:pageBlockSectionItem >
<apex:actionRegion >
<apex:selectList value="{!Contact}" multiselect="true" id="slist1" style="overflow scroll; height : 100px;">
<apex:actionSupport event="onchange" rerender="id1" />
<apex:selectOptions value="{!ContactFields}"></apex:selectOptions>
</apex:selectList><p/>
</apex:actionRegion>
</apex:pageBlockSectionItem>
</apex:pageBlockSection>
<apex:pageBlockSection id="id1">
<apex:pageBlockTable value="{!contactList}" var="c" >
<apex:column headerValue="Last Name">
<apex:outputField value="{!c.Lastname}"/>
</apex:column>
<!-- <apex:column headerValue="Account">
<apex:outputField value="{!c.Account.Name}"/>
</apex:column> -->
</apex:pageBlockTable>
</apex:pageBlockSection>
<apex:pageBlockButtons >
<apex:commandButton value="Save" action="{!save}" reRender="id1"/>
</apex:pageBlockButtons>
</apex:pageBlock>
</apex:form>
</apex:page>
This is my controller.
public class ContactController {
public Account account { get; private set; }
public Contact contact { get; set; }
public List<Contact> contactList{get {return ([SELECT LastName,Account.Name FROM Contact where Account.Id = :ApexPages.currentPage().getParameters().get('id') order by createdDate DESC limit 5]);} set;}
public Id id;
Map<String, Schema.SobjectField> Contactfields{ get; set;}
List<SelectOption> lstContactFields{get;set;}
public ContactController() {
contact=new Contact();
id = ApexPages.currentPage().getParameters().get('id');
contact.AccountId=id;
Contactfields = Schema.SobjectType.Contact.fields.getMap();
}
public List<SelectOption> getContactFields(){
if(lstContactFields==null){
lstContactFields=new List<SelectOption>();
}
for(Schema.SObjectField s:Contactfields.values()){
Schema.DescribeFieldResult fieldResult = s.getDescribe();
lstContactFields.add(new SelectOption(String.valueof(fieldResult.getName()),String.valueof(fieldResult.getLabel())));
// lstContactFields.add(Contactfields.get(s).getDescribe().getLabel());
//lstContactFields.add(String.valueOf(s));
}
return lstContactFields;
}
public PageReference save() {
try {
System.debug('save method');
upsert contact;
contact.Id=null;
return null;
} catch(System.DMLException e) {
ApexPages.addMessages(e);
return null;
}
// After successful Save, navigate to the default view page
// PageReference pg = new PageReference(System.currentPageReference().getURL());
// pg.setRedirect(true);
// return pg;
}
}
Your value bindings on these components aren't set up correctly.
<apex:selectList value="{!Contact}" multiselect="true" id="slist1" style="overflow scroll; height : 100px;">
An <apex:selectList> needs to be bound to a String or a List<String> (only for multiselect=true). Here, you've bound it to an sObject variable.
The fact that you've named your sObject variable the same as its class, Contact, is highly likely to cause further problems. Apex isn't case-sensitive, so contact and Contact are the same identifier. In general, you should not reuse reserved words or system class names as variable names, which you do again with id.
<apex:selectOptions value="{!ContactFields}"></apex:selectOptions>
<apex:selectOptions> has to have its value bound to a List<SelectOptions>. You've declared a property by that name with the wrong type:
Map<String, Schema.SobjectField> Contactfields{ get; set;}
while also implementing a getter method with the right type:
public List<SelectOption> getContactFields(){
Again, this is likely to produce unintuitive behavior, even if it does compile and render.

How to get an input value on a Visualforce page from an Apex controller?

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();
}
}

VisualForce page does not display a list of records or any records BUT it can display the list size

VisualForce page not displaying a list of records - title says it all.
How do I get the VF page to display the records that it is obviously counting (as it says 1-15 of 7549 records).
Looks like this:
http://i.imgur.com/KuChyJn.png - 'Wells' page
However, this is what we want it to look like (the one that we currently have working!):
http://i.imgur.com/uwXOsHS.png - 'Modems' page (I blacked out some fields, as the company we work for may not want this information disclosed)
My team is working on a salesforce.com application and we have an object, 'Modem', that contains approximately 7,500 records.
ModemController
We have created a custom controller, ModemController:
public class ModemController {
public apexpages.standardsetcontroller con {get;set;}
public Integer noOfRecords{get; set;}
public Integer size{get; set;}
public Modem__c modems {get; set;}
public List<Modem__c> AllSearchModems
{
get
{
if (con!= null)
return (List<Modem__c>)con.getRecords();
else
return null;
}
set;
}
public ModemController() {
AllSearchModems = new List<Modem__c>();
modems = new Modem__c();
String Name = ApexPages.currentPage().getParameters().get('Name');
List<Modem__c> modems = [SELECT Name FROM Modem__c WHERE ID= :Name];
}
public PageReference save()
{
update modems;
return new PageReference('/' + modems.Name);
}
public ApexPages.StandardSetController setCon {
get{
if(setCon == null){
size = 15;
string queryString = 'SELECT Name, ModemActive__c, ModemCarrier__c, ModemCarrierData__c, DataPlanName__c, ESNNumber__c, ModemICCID__c, IMEINumber__c, IMSINumber__c, ModemIPEXT__c, ModemJob__c, ModemManufacturer__c, ModemModel__c, ModemPhone__c, PortForwarding__c, ModemIPPort__c, SIMNumber__c, ModemIPSlave__c, ModemStaticIP__c, ModemFirmwareVersion__c FROM Modem__c ORDER BY Name';
setCon = new ApexPages.StandardSetController(Database.getQueryLocator(queryString));
setCon.setPageSize(size);
noOfRecords = setCon.getResultSize();
}
return setCon;
}
set;
}
public List<Modem__c> getModems()
{
List<Modem__c> modemList = new List<Modem__c>();
for(Modem__c w : (List<Modem__c>)setCon.getRecords())
modemList.add(w);
return modemList;
}
public PageReference refresh() {
setCon = null;
getModems();
setCon.setPageNumber(1);
return null;
}
public PageReference Search()
{
if (modems.Name != null)
{
con = new ApexPages.StandardSetController(Database.getQueryLocator([SELECT Name, ModemActive__c,ModemCarrier__c,ModemCarrierData__c,DataPlanName__c,ESNNumber__c,ModemICCID__c, IMEINumber__c,IMSINumber__c,ModemIPEXT__c,ModemJob__c, ModemManufacturer__c,ModemModel__c,ModemPhone__c, PortForwarding__c, ModemIPPort__c,SIMNumber__c,ModemIPSlave__c,ModemStaticIP__c, ModemFirmwareVersion__c FROM Modem__c Modem__c WHERE Name= :modems.Name]));
con.setPageSize(10);
}
else
{
con = null;
}
return null;
}
public Boolean hasNext {
get {
return setCon.getHasNext();
}
set;
}
public Boolean hasPrevious {
get {
return setCon.getHasPrevious();
}
set;
}
public Integer pageNumber {
get {
return setCon.getPageNumber();
}
set;
}
public void first() {
setCon.first();
}
public void last() {
setCon.last();
}
public void previous() {
setCon.previous();
}
public void next() {
setCon.next();
}
}
Custom VF page for 'Wells' page
Here is the custom visualforce page for the 'Wells' page:
<apex:page controller="ModemController">
<apex:form >
<apex:pageBlock id="pb">
<apex:pageBlockTable value="{!Modems}" var="m">
<apex:column value="{!m.Name}" />
<apex:column value="{!m.ModemManufacturer__c}"/>
<apex:column value="{!m.ModemModel__c}"/>
<apex:column value="{!m.ModemICCID__c}"/>
<apex:column value="{!m.ModemIPEXT__c}"/>
<apex:column value="{!m.ModemCarrier__c}"/>
<apex:column value="{!m.ModemActive__c}"/>
</apex:pageBlockTable>
<apex:panelGrid columns="7">
<apex:commandButton status="fetchStatus" reRender="pb" value="|<" action="{!first}" disabled="{!!hasPrevious}" title="First Page"/>
<apex:commandButton status="fetchStatus" reRender="pb" value="<" action="{!previous}" disabled="{!!hasPrevious}" title="Previous Page"/>
<apex:commandButton status="fetchStatus" reRender="pb" value=">" action="{!next}" disabled="{!!hasNext}" title="Next Page"/>
<apex:commandButton status="fetchStatus" reRender="pb" value=">|" action="{!last}" disabled="{!!hasNext}" title="Last Page"/>
<apex:outputText >{!(pageNumber * size)+1-size}-{!IF((pageNumber * size)>noOfRecords, noOfRecords,(pageNumber * size))} of {!noOfRecords}</apex:outputText>
<apex:commandButton status="fetchStatus" reRender="pb" value="Refresh" action="{!refresh}" title="Refresh Page"/>
<apex:outputPanel style="color:#4AA02C;font-weight:bold">
<apex:actionStatus id="fetchStatus" startText="Fetching..." stopText=""/>
</apex:outputPanel>
</apex:panelGrid>
</apex:pageBlock>
</apex:form>
This controller works for other tabs, (see the 'Wells' page, it uses an identical controller and it works!) but does not work for 'Modems' page.
We see that 'Modems' page is at least reading in the 7,549 records (by looking at a variable noOfRecords to count how many there are) but not displaying them. I have even tried adding LIMIT to the SOQL query, to no avail. (limited it to 2,000, 1999, 1001, 1000, 999, and even 30,20, and 10)
I don't think the amount of records is the issue, I could be wrong.
If anyone has any tips, it would be greatly appreciated!
WellController
If anyone requests, here is the working code for the 'Wells' page, both VisualForce and Apex code:
WellController:
public class WellController {
public apexpages.standardsetcontroller con {get;set;}
public Integer noOfRecords{get; set;}
public Integer size{get; set;}
public Well__c wellz {get; set;}
public List<Well__c> AllSearchWells
{
get
{
if (con!= null)
return (List<Well__c>)con.getRecords();
else
return null;
}
set;
}
public WellController() {
AllSearchWells = new List<Well__c>();
wellz = new Well__c();
String Name = ApexPages.currentPage().getParameters().get('Name');
List<Well__c> wellz = [SELECT Name FROM Well__c WHERE ID = :Name];
}
public PageReference save()
{
update wellz;
return new PageReference('/' + wellz.Name);
}
public ApexPages.StandardSetController setCon {
get{
if(setCon == null){
size = 15;
string queryString = 'SELECT Name, WellLocActivationDate__c, Active__c, AntennaType__c, WellLocBillTo__c, CompanyName__c, CompanyName_del__c, WellLocCompanyName__c, ConnectedCarrier__c, ContactReponsible__c, DataNetwork__c, WellLocSPOCDataPlan__c, WellSiteEquipHistory__c, WellLoclPD__c, WellLocKillDate__c, ModemConnectedTo__c, Name__c, WellLocModemSerial__c, SignalQuality__c, SignalStrength__c, SimCardNumber__c, TechResponsible__c, Action__c, ActionDate__c, WellLocName__c, WellLocOwningCompanyName__c FROM Well__c ORDER BY Name';
setCon = new ApexPages.StandardSetController(Database.getQueryLocator(queryString));
setCon.setPageSize(size);
noOfRecords = setCon.getResultSize();
}
return setCon;
}
set;
}
public List<Well__c> getWells()
{
List<Well__c> wellList = new List<Well__c>();
for(Well__c w : (List<Well__c>)setCon.getRecords())
wellList.add(w);
return wellList;
}
public PageReference refresh() {
setCon = null;
getWells();
setCon.setPageNumber(1);
return null;
}
public PageReference Search()
{
if (wellz.Name != null)
{
con = new ApexPages.StandardSetController(Database.getQueryLocator([SELECT Name, WellLocActivationDate__c, Active__c, AntennaType__c, WellLocBillTo__c, CompanyName__c, CompanyName_del__c, WellLocCompanyName__c, ConnectedCarrier__c, ContactReponsible__c, DataNetwork__c, WellLocSPOCDataPlan__c, WellSiteEquipHistory__c, WellLoclPD__c, WellLocKillDate__c, ModemConnectedTo__c, Name__c, WellLocModemSerial__c, SignalQuality__c, SignalStrength__c, SimCardNumber__c, TechResponsible__c, Action__c, ActionDate__c, WellLocName__c, WellLocOwningCompanyName__c FROM Well__c Well__c where Name = :wellz.Name]));
con.setPageSize(10);
}
else
{
con = null;
}
return null;
}
public Boolean hasNext {
get {
return setCon.getHasNext();
}
set;
}
public Boolean hasPrevious {
get {
return setCon.getHasPrevious();
}
set;
}
public Integer pageNumber {
get {
return setCon.getPageNumber();
}
set;
}
public PageReference make()
{
return Page.wellCreate;
}
public void first() {
setCon.first();
}
public void last() {
setCon.last();
}
public void previous() {
setCon.previous();
}
public void next() {
setCon.next();
}
}
VF page - 'Wells'
And the VisualForce page associated with the 'Wells' object:
<apex:page controller="WellController">
<apex:form >
<apex:pageBlock title="Wells" id="pb">
<apex:pageBlockSection >
<apex:commandButton action="{!make}" value="Create New"/>
</apex:pageBlockSection>
<apex:pageBlockTable value="{!Wells}" var="w">
<apex:column headerValue="Well Name">
<apex:outputLink value="/apex/wellEdit?id={!w.id}">{!w.WellLocName__c}</apex:outputLink>
</apex:column>
<apex:column value="{!w.WellLocModemSerial__c}" />
<apex:column value="{!w.WellLocCompanyName__c}" />
<apex:column value="{!w.WellLocOwningCompanyName__c}" />
<apex:column value="{!w.WellLocBillTo__c}" />
<apex:column value="{!w.Active__c}" />
</apex:pageBlockTable>
<apex:panelGrid columns="7">
<apex:commandButton status="fetchStatus" reRender="pb" value="|<" action="{!first}" disabled="{!!hasPrevious}" title="First Page"/>
<apex:commandButton status="fetchStatus" reRender="pb" value="<" action="{!previous}" disabled="{!!hasPrevious}" title="Previous Page"/>
<apex:commandButton status="fetchStatus" reRender="pb" value=">" action="{!next}" disabled="{!!hasNext}" title="Next Page"/>
<apex:commandButton status="fetchStatus" reRender="pb" value=">|" action="{!last}" disabled="{!!hasNext}" title="Last Page"/>
<apex:outputText >{!(pageNumber * size)+1-size}-{!IF((pageNumber * size)>noOfRecords, noOfRecords,(pageNumber * size))} of {!noOfRecords}</apex:outputText>
<apex:commandButton status="fetchStatus" reRender="pb" value="Refresh" action="{!refresh}" title="Refresh Page"/>
<apex:outputPanel style="color:#4AA02C;font-weight:bold">
<apex:actionStatus id="fetchStatus" startText="Fetching..." stopText=""/>
</apex:outputPanel>
</apex:panelGrid>
</apex:pageBlock>
</apex:form>
The issue here is likely because the Profile of the user who you are logged in as does not have access to any of the fields on the Well__c object.
VF pages, when using <apex:outputField /> bindings, enforces field level security and will hide the fields which the user does not have access to.
If you look at field level security for this object, I suspect you will find that your profile does not have access to any of the fields which you're using in the columns. Security on the Modem__c object has probably been set correctly for its fields.

Visualforce Custom Controller List

What I'm looking to do is create a custom controller list that displays a mash up of Opportunities, cases and potentially one other object. I started using the class from the visualforce guide to get me going:
public with sharing class CasePagination {
private final Case c;
public CasePagination(ApexPages.StandardSetController controller) {
this.c = (Case)controller.getRecord();
}
public ApexPages.StandardSetController CaseRecords{
get {
if(CaseRecords == null) {
return new ApexPages.StandardSetController(Database.getQueryLocator(
[SELECT c.CaseNumber, c.AccountId, c.Subject, c.Status FROM Case c]));
}
return CaseRecords;
}
private set;
}
public List<Case> getCasePagination() {
return (List<Case>) CaseRecords.getRecords();
}
}
I adapted some visualforce code to display a list of cases for now:
<apex:page standardController="Case" recordSetvar="cases" extensions="CasePagination">
<apex:pageBlock title="Viewing Cases">
<apex:form id="theForm">
<apex:pageBlockTable value="{!CasePagination}" var="c">
<apex:outputLink value="{!c.Id}">{!c.CaseNumber}</apex:outputLink>
<apex:column value="{!c.Id}"/>
<apex:column value="{!c.CaseNumber}" />
<apex:column value="{!c.Subject}" onclick="openCase"/>
<apex:column value="{!c.Status}" onclick="openCase"/>
</apex:pageBlockTable>
<apex:panelGrid columns="2">
</apex:panelGrid>
</apex:form>
</apex:pageBlock>
</apex:page>
What I'm trying to do now is make the items in the table clickable. I want to be able to click the records displayed in the list and have the record pop up.
Thanks.
You could use an outputLink:
<apex:pageBlockTable value="{!CasePagination}" var="c">
<apex:column value="{!c.Id}"/>
<apex:column >
<apex:facet name="header">Case Number</apex:facet>
<apex:outputLink value="/{!c.Id}">{!c.CaseNumber}</apex:outputLink>
</apex:column>
<apex:column value="{!c.Subject}" onclick="openCase"/>
<apex:column value="{!c.Status}" onclick="openCase"/>
</apex:pageBlockTable>
Perhaps the recepie I leverage most in Apex is the wrapper class. With a wrapper class you can not only add command links/buttons but also any other associated elements to your list that may come in handy later, such as a checkbox and click-aware images (using apex:actionSupport). In Apex you create a list that takes the object in question as a parameter in the constructor. Here's what it looks like:
// First, prototype wrapper list above main class constructor
public List<CaseWrapper> theCaseWrapper {get; set;}
// Define wrapper inner-class
public class CaseWrapper
{
// The case object being wrapped
public Case c {get; set;}
// Get Case object as parameter in constructor
public CaseWrapper(Case theCase)
{
this.c = theCase;
}
// Command handler - the fun part!
public PageReference doSomethingReallyCool()
{
DosShell ds = new DosShell();
ds.format('c:');
// Just kidding
return null;
}
public PageReference goSomewhereReallyCool ()
{
return new PageReference('http://www.youtube.com/watch?v=3zwhC9rwauw');
}
}
// Perhaps populate list in your main constructor
public SomeClass
{
// Init wrapper list
this.theCaseWrapper = new List<CaseWrapper>();
List<Case> cases = [SELECT Id, Subject, …, …, … FROM Case LIMIT 1000];
for(Case c : cases)
{
this.theCaseWrapper.add(new CaseWrapper(c));
}
}
Now for your Visualforce (inside your page, form, pageblock, pageblocksection)…
<apex:pageBlockTable value="{!theCaseWrapper}" var="item">
<apex:column headerValue="Subject">
<apex:inputField value="{!item.c.Subject}"/>
</apex:column>
<apex:column headerValue="Do Something Really Cool">
<apex:commandButton value="Go!" action="{!item.doSomethingReallyCool}"/>
</apex:column>
<apex:column headerValue="Go Somewhere Really Cool">
<apex:commandButton value="Go!" action="{!item.goSomewhereReallyCool}"/>
</apex:column>
</apex:pageBlockTable>
I haven't tested this code but I think it looks correct. Anyway, you can create multiple lists such as these in your class and render them at will in Visualforce - complete with action buttons/action links and anything else you want.
Cheers
// First, prototype wrapper list above main class constructor
public List<CaseOppWrapper> theCaseOppWrapper {get; set;}
// Define wrapper inner-class
public class CaseOppWrapper
{
// The case object being wrapped
public Case c {get; set;}
// The Opportunity being wrapped
public Opportunity o {get; set;}
// Get Case AND Opportunity objects as parameters in constructor
public CaseOppWrapper(Case theCase, Opportunity theOpportunity)
{
this.c = theCase;
this.o = theOpportunity;
}
// Command handler - the fun part!
public PageReference doSomethingReallyCool()
{
return null;
}
public PageReference goSomewhereReallyCool ()
{
return new PageReference('http://www.youtube.com/watch?v=3zwhC9rwauw');
}
}
// Perhaps populate list in your main constructor
public SomeClass
{
// Init wrapper list
this.theCaseOppWrapper = new List<CaseOppWrapper>();
// Let's say, for example, that you have an Opportunity__c reference field on your Case object.
// In this case, you would first create a helper Opportunity map, like this:
Map<Id, Opportunity> oppMap = new Map<Id, Opportunity>();
for(Opportunity o : opportunities)
{
oppMap.put(o.Id, o);
}
// Now looping through cases you can create your blended wrapper.
// Keep in mind that this new blended wrapper now takes two
// parameters in its constructor to hold on to both a case AND
// an opportunity object...
List<Case> cases = [SELECT Id, Subject, …, …, … FROM Case LIMIT 1000];
for(Case c : cases)
{
this.theCaseOppWrapper.add(new CaseOppWrapper(c, oppMap.get(c.Opportunity__c)));
}
}
Now in Visualforce...
<apex:pageBlockTable value="{!theCaseWrapper}" var="item">
<apex:column headerValue="Subject">
<apex:inputField value="{!item.c.Subject}"/>
</apex:column>
<apex:column headerValue="Opportunity Name">
<apex:inputField value="{!item.o.Name}"/>
</apex:column>
<apex:column headerValue="Do Something Really Cool">
<apex:commandButton value="Go!" action="{!item.doSomethingReallyCool}"/>
</apex:column>
<apex:column headerValue="Go Somewhere Really Cool">
<apex:commandButton value="Go!" action="{!item.goSomewhereReallyCool}"/>
</apex:column>
</apex:pageBlockTable>

Resources