why am i not getting the data of record and just lable in visualforce page? - salesforce

attched is my output
enter image description here
Bolow is my visulforce Page and apex page
i am expecting output as a single record in 2 column and has next and previous button to next and previous record.
//apex
public with sharing class MyController
{
public list<Patient__c> objectList = new List<Patient__c>();
public list<Patient__c> currentObject {get; set;}
public integer i;
public MyController(ApexPages.StandardSetController controller) {myAction();}
public string selectedValue {get; set;}
public boolean myBoolean {get; set;}
public void myAction()
{
if ( selectedValue == 'List View') { myBoolean = True; }
else { myBoolean = False ;}
}
public Patient__c getCurrentObject()
{
return currentObject[i];
}
public void goToPrevious(){
if (i>0){i--;}
}
public void goToNext() {
if (i < currentObject.size() - 1) {
i++;
}
}
/* public void goToRecord (Id recordId) {
for (Integer i = 0; i < objectList.size(); i++) {
if (objectList[i].Id == recordId) {
i = i;
break;
}
}
} */
}
Below is my visualforce page code.
<apex:page standardController="Patient__c" extensions="MyController" recordSetVar="Patients">
<apex:pageBlock title="Patient Records...!!!">
<apex:form >
<div align='center' style=' color:blue;font-size:10px '>
Your selection is {!selectedValue}
</div>
<apex:selectList label="View Type" value="{!selectedValue}" size="1">
<apex:selectOption itemvalue="Standared View" itemLabel="Standared View"/>
<apex:selectOption itemvalue="List View" itemLabel="List View"/>
<apex:actionSupport event="onchange" action="{!myAction}" >
</apex:actionSupport>
</apex:selectList>
</apex:form>
<apex:pageBlock rendered="{!myBoolean}">
<apex:pageBlockTable value="{!Patients}" var="Pa" >
<apex:column value="{!Pa.Name}"/>
<apex:column value="{!Pa.Contact_Number__c}"/>
<apex:column value="{!Pa.Email__c}"/>
<apex:column value="{!Pa.Age__c}"/>
</apex:pageBlockTable>
</apex:pageBlock>
<apex:pageBlock title="Standared View" rendered="{!!myBoolean}">
<apex:pageBlockSection columns="2">
<apex:outputField value="{!Patient__c.Name}"/>
<apex:outputField value="{!Patient__c.Age__c}"/>
<apex:outputField value="{!Patient__c.Email__c}"/>
</apex:pageBlockSection>
<apex:form >
<apex:commandButton value="Previous" action="{!goToPrevious}" />
<apex:commandButton value="Next" action="{!goToNext}"/>
</apex:form>
</apex:pageBlock>
</apex:pageBlock>
</apex:page>
I am expecting as a single record showing page where have next and previous button to go net and previous record.

Related

Edit button not redirecting on Salesforce mobile app

On Account page, I have a Button which opens a VF page which creates Task record. When I click Edit button on the Task record to update it and click Save, it's redirecting to the Task record page on Desktop in both classic and lightning mode. However, when I am performing same action on Mobile, upon clicking on Save, it is giving me error. Page doesn't exist. Enter a valid URL and try again.
public class Sim_NewTaskController {
//private Task taskObjectParent;
public Task taskObjectParent{get;set;}
private Task tempTask;
public String whoId{get;set;}
public String whatId{get;set;}
public String recordId{get;set;}
public String retURL{get;set;}
private String close;
// these three variables will set when log a call button will clicked on activity history
private String title;
private String tsk5;
private String followup;
public String inputValue{get;set;}
public List<MultiSelect> avaiableContactlList {get;set;}
public List<MultiSelect> avaiableGoalList {get;set;}
public List<MultiSelect> avaiableTopicList {get;set;}
public boolean isNAOProfile{get;set;}
public Integer totalAvaiableGoal {get;set;}
public Integer totalAvaiableTopic {get;set;}
public List<SelectOption> avaiableOptionsContacts{get;set;}
public String selectedContact{get;set;}
public string searchstring {get;set;}
//For SOS Profile
//Set<String> setSOSAvlTopics = new Set<String>{'Account Maintenance', 'Co-Management','Material Request','Referral Process','Divisions','Events','Issue Resolution','New Provider'};
public Sim_NewTaskController(ApexPages.StandardController stdController) {
totalAvaiableGoal = 0;
totalAvaiableTopic = 0;
//this.taskObjectParent = (Task)stdController.getRecord();
avaiableOptionsContacts = new List<SelectOption>();
selectedContact = searchText = '';
tempTask=new Task();
taskObjectParent=new Task();
whatId = ApexPages.currentPage().getParameters().get('what_id');
whoId = ApexPages.currentPage().getParameters().get('who_id');
recordId = ApexPages.currentPage().getParameters().get('id');
close = ApexPages.currentPage().getParameters().get('close');
retURL = ApexPages.currentPage().getParameters().get('retURL');
title = ApexPages.currentPage().getParameters().get('title');
tsk5 = ApexPages.currentPage().getParameters().get('tsk5');
followup = ApexPages.currentPage().getParameters().get('followup');
CheckProfile();
}
public void CheckProfile(){
isNAOProfile=false;
//If Logged in user prfile is NAO profile then replace picklist value like below
//Get looged in user profile
User objUser=[select profile.Name from user where id=:UserInfo.getUserId()];
if(objUser!=null && objUser.profile.Name=='NAO Profile'){
isNAOProfile=true;
}
}
public void filterFields() {
//Get Profile Name of logged in user
string profileName=[select profile.Name from user where id=:UserInfo.getUserId()].profile.Name;
System.debug('taskObjectParent.type------------'+taskObjectParent.type);
avaiableGoalList = new List<MultiSelect>();
avaiableTopicList = new List<MultiSelect>();
if(taskObjectParent.type == 'Sports Medicine Phone Call' || taskObjectParent.type == 'Sports Medicine Visit') {
avaiableTopicList.add(new MultiSelect(false, '2 Day Athlete Guarantee', null));
avaiableTopicList.add(new MultiSelect(false, 'Athletic Training Protocols', null));
avaiableTopicList.add(new MultiSelect(false, 'Divisions', null));
avaiableTopicList.add(new MultiSelect(false, 'Events', null));
avaiableTopicList.add(new MultiSelect(false, 'Hospitals', null));
avaiableTopicList.add(new MultiSelect(false, 'Issue Resolution', null));
avaiableTopicList.add(new MultiSelect(false, 'Material Request', null));
avaiableTopicList.add(new MultiSelect(false, 'Medical Coverage', null));
avaiableTopicList.add(new MultiSelect(false, 'New Clinic', null));
avaiableTopicList.add(new MultiSelect(false, 'New Physicians', null));
avaiableTopicList.add(new MultiSelect(false, 'Quality Outcomes', null));
avaiableTopicList.add(new MultiSelect(false, 'Referral Process', null));
avaiableTopicList.add(new MultiSelect(false, 'Sports Injury Clinics', null));
avaiableTopicList.add(new MultiSelect(false, 'Sponsorships', null));
avaiableTopicList.add(new MultiSelect(false, 'Team Physicals', null));
avaiableGoalList.add(new MultiSelect(false, 'Establishing New Relationships', null));
avaiableGoalList.add(new MultiSelect(false, 'Maintaining Relationship', null));
avaiableGoalList.add(new MultiSelect(false, 'Service Update', null));
}
if(taskObjectParent.type == 'E-mail or Fax' || taskObjectParent.type == 'Follow-Up' || taskObjectParent.type == 'Mailed Collateral/Document' || taskObjectParent.type == 'Office Staff Meeting' || taskObjectParent.type =='Outreach or CME Event' || taskObjectParent.type == 'Out of the Field' || taskObjectParent.type == 'Phone Call' || taskObjectParent.type == 'Unsuccessful Visit' ){
avaiableTopicList.add(new MultiSelect(false, 'Account Maintenance', null));
avaiableTopicList.add(new MultiSelect(false, 'Co-Management', null));
avaiableTopicList.add(new MultiSelect(false, 'Material Request', null));
avaiableTopicList.add(new MultiSelect(false, 'Referral Process', null));
avaiableTopicList.add(new MultiSelect(false, 'Divisions', null));
avaiableTopicList.add(new MultiSelect(false, 'Events', null));
avaiableTopicList.add(new MultiSelect(false, 'Issue Resolution', null));
avaiableTopicList.add(new MultiSelect(false, 'New Provider', null));
avaiableTopicList.add(new MultiSelect(false, 'Urgent Ortho/Walk-In', null));
}
else {
avaiableTopicList.add(new MultiSelect(false, 'Account Maintenance', null));
avaiableTopicList.add(new MultiSelect(false, 'Co-Management', null));
avaiableTopicList.add(new MultiSelect(false, 'Material Request', null));
avaiableTopicList.add(new MultiSelect(false, 'Referral Process', null));
avaiableTopicList.add(new MultiSelect(false, 'Divisions', null));
avaiableTopicList.add(new MultiSelect(false, 'Events', null));
avaiableTopicList.add(new MultiSelect(false, 'Quality Outcomes', null));
avaiableTopicList.add(new MultiSelect(false, 'Issue Resolution', null));
avaiableTopicList.add(new MultiSelect(false, 'New Provider', null));
avaiableTopicList.add(new MultiSelect(false, 'Urgent Ortho/Walk-In', null));
/* if(profileName=='SOS Profile'){
for(String st:setSOSAvlTopics){
avaiableTopicList.add(new MultiSelect(false, st, null));
}
}*/
for( Schema.PicklistEntry f : Task.Goal_of_Activity__c.getDescribe().getPicklistValues()) {
if(isNAOProfile==true){
if(f.getValue()!='CORE Referral Manager Training'){
avaiableGoalList.add(new MultiSelect(false, f.getLabel(), null));
}
}
else{
avaiableGoalList.add(new MultiSelect(false, f.getLabel(), null));
}
}
}
//For Goal
system.debug(taskObjectParent.Id + ' =====> ' + taskObjectParent.Goal_of_Activity__c);
if(string.isNotBlank(taskObjectParent.Goal_of_Activity__c)){
for(MultiSelect goal : avaiableGoalList){
for(string str:taskObjectParent.Goal_of_Activity__c.split(';')){
if(goal.Name == str.trim()){
goal.isChecked = true;
}
}
}
totalAvaiableGoal = taskObjectParent.Goal_of_Activity__c.split(';').size();
}
system.debug('avaiableGoalList--111------------->' + avaiableGoalList);
/*if(isNAOProfile==true){
avaiableTopicList = new List<MultiSelect>();
avaiableTopicList.add(new MultiSelect(false, 'Account Maintenance', null));
avaiableTopicList.add(new MultiSelect(false, 'Divisions', null));
avaiableTopicList.add(new MultiSelect(false, 'Events', null));
avaiableTopicList.add(new MultiSelect(false, 'Issue Resolution', null));
avaiableTopicList.add(new MultiSelect(false, 'NAO Material Request', null));
avaiableTopicList.add(new MultiSelect(false, 'New Clinic', null));
avaiableTopicList.add(new MultiSelect(false, 'New Physician', null));
avaiableTopicList.add(new MultiSelect(false, 'NAO Referral Process', null));
avaiableTopicList.add(new MultiSelect(false, 'Quality Outcomes', null));
avaiableTopicList.add(new MultiSelect(false, 'Urgent Ortho', null));
}*/
//For Topics
system.debug(taskObjectParent.Id + ' =====> ' + taskObjectParent.Topics_Discussed__c);
if(string.isNotBlank(taskObjectParent.Topics_Discussed__c)){
for(MultiSelect goal : avaiableTopicList){
for(string str:taskObjectParent.Topics_Discussed__c.split(';')){
if(goal.Name == str.trim()){
goal.isChecked = true;
}
}
}
totalAvaiableTopic = taskObjectParent.Topics_Discussed__c.split(';').size();
}
system.debug('avaiableTopicList--2222------------->' + avaiableTopicList);
}
// Task cannot be created from contact. Button hidden
public PageReference loadNewTask(){
try{
taskObjectParent=new Task();
//Assign default value
taskObjectParent.ActivityDate=Date.Today();
if(recordId != null){
List<Task> taskList = [select whatId,whoId,ActivityDate ,Priority ,Status,
Activity_Cost__c,OwnerId,Visit_Duration__c,Description,Goal_of_Activity__c ,
Topics_Discussed__c,Subject, Type
from task where id=:recordId limit 1];
if(taskList!= null && taskList.size()>0)
{
taskObjectParent=taskList[0];
whatId = taskList[0].whatId;
whoId = taskList[0].whoId;
inputValue = taskList[0].Type;
}
}
if((whatId != null && !whatId.startsWith('001')) || (whoId!=null && !whoId.startsWith('003'))){
PageReference refObject = new PageReference('/00T/e');
refObject.getParameters().putAll(ApexPages.currentPage().getParameters());
refObject.getParameters().put('nooverride', '1');
refObject.setRedirect(true);
return refObject;
}else{
avaiableContactlList = new List<MultiSelect>();
filterFields();
//We do not create task through contact
if(whatId != null && whatId.startsWith('001')){
//get Account Id to fileter contact based on profile
Set<string> setAccountId=new Set<string>();
if(Test.isRunningTest()){
setAccountId.add(whatId);
}
string labelActId=Label.Core_Account_Id;
if(isNAOProfile==true){
labelActId=Label.NAO_Account_Id;
}
if(string.isNotBlank(labelActId)){
for(string st:labelActId.split(',')){
setAccountId.add(st);
}
for(Contact contactObject : [Select id,Name,Email, AccountId From Contact where
RecordType.Name='Internal Provider' AND Inactive__c = false order by Name]){
avaiableContactlList.add(new MultiSelect(false, contactobject.Name, contactObject.Id));
avaiableOptionsContacts.add(new SelectOption(contactObject.Id, contactObject.Name));
}
}
taskObjectParent.WhatId = whatId;
taskObjectParent.OwnerId = Userinfo.getUserId();
}
if(close != null && close =='1'){
taskObjectParent.Status = 'Completed';
}
// when task is created from log a call
System.debug('title > '+ title + 'followup > '+ followup + 'tsk5 > '+ tsk5);
if(title != null && title =='Referral Meeting' && followup !=null && followup == '1' && tsk5 != null && tsk5 == 'Referral Meeting'){
taskObjectParent.Status = 'Completed';
taskObjectParent.Type = title;
}
return null;
}
//return null;
}catch(Exception e){
ApexPages.addMessage(new ApexPages.message(ApexPages.severity.FATAL,e.getMessage()));
return null;
}
}
public String searchText{get;set;}
public PageReference filterContacts(){
for(MultiSelect option : avaiableContactlList){
if(String.isBlank(searchText)){
option.isDisplay = '';
continue;
}
if(!option.Name.contains(searchText)){
option.isDisplay = 'none';
}
}
return null;
}
// for all activity objectives except 'Physician to physician visit' contact is not required.
public PageReference performSave(){
System.debug('############');
try{
string retId=ApexPages.currentPage().getParameters().get('retURL');
system.debug('retId------------>' + retId);
system.debug('recordId------------>' + recordId);
if(string.isBlank(retId)==null || retId==null){
retId=recordId;
}
system.debug('retId111------------>' + retId);
if(string.isBlank(retId)){
if(string.isNotblank(whatId)){
retId=whatId;
}
if(string.isNotblank(whoId)){
retId=whoId;
}
}
system.debug('retId222------------>' + retId);
//String retId = ApexPages.currentPage().getParameters().get('retURL');
boolean isContactSelected = false;
for(MultiSelect conObj : avaiableContactlList){
if(conObj.isChecked){
isContactSelected = true;
break;
}
}
List<Task> tasksToBeSaved = new List<Task>();
if(recordId == null){
if((taskObjectParent.Type == 'Physician-to-Physician Visit' || taskObjectParent.Type == 'Unsuccessful Physician-to-Physician Visit' || taskObjectParent.Type == 'Sports Medicine Phone Call' || taskObjectParent.Type =='Sports Medicine Visit') && isContactSelected == true){
for(MultiSelect conObj : avaiableContactlList){
if(conObj.isChecked){
Task taskObject = createTask(taskObjectParent,conObj.Value);
taskObject.Topics_Discussed__c = '';
taskObject.Goal_of_Activity__c = '';
for(MultiSelect sltVal : avaiableTopicList){
if(sltVal.isChecked){
taskObject.Topics_Discussed__c += sltVal.Name + ';';
}
}
for(MultiSelect sltVal : avaiableGoalList){
if(sltVal.isChecked){
taskObject.Goal_of_Activity__c += sltVal.Name + ';';
}
}
tasksToBeSaved.add(taskObject);
}
}
}else{
Task taskObject = createTask(taskObjectParent,null);
taskObject.Topics_Discussed__c = '';
taskObject.Goal_of_Activity__c = '';
for(MultiSelect sltVal : avaiableTopicList){
if(sltVal.isChecked){
taskObject.Topics_Discussed__c += sltVal.Name + ';';
}
}
for(MultiSelect sltVal : avaiableGoalList){
if(sltVal.isChecked){
taskObject.Goal_of_Activity__c += sltVal.Name + ';';
}
}
tasksToBeSaved.add(taskObject);
}
system.debug(' >>>>> === '+tasksToBeSaved);
upsert tasksToBeSaved;
system.debug(' >>>>> ------'+tasksToBeSaved);
system.debug('retId44------------>' + retId);
System.debug(' Current Url -- '+ApexPages.currentPage().getHeaders().get('Origin'));
System.debug(' > >> > >> > '+Apexpages.currentPage().getUrl());
//PageReference pg = new PageReference('/'+ApexPages.currentPage().getParameters().get('retURL'));
//PageReference pg = new PageReference('/'+retId);
System.debug(' >> > > > 299 = = = '+retId);
PageReference pg = new PageReference(retId);
pg.setRedirect(true);
return pg;
// return null;
}else{
if(((taskObjectParent.Type == 'Physician-to-Physician Visit' && inputValue != 'Physician-to-Physician Visit' ) || (taskObjectParent.Type == 'Sports Medicine Visit' && inputValue != 'Sports Medicine Visit') || (taskObjectParent.Type == 'Sports Medicine Phone Call' && inputValue != 'Sports Medicine Phone Call') ) && isContactSelected == true){
for(MultiSelect conObj : avaiableContactlList){
if(conObj.isChecked){
Task taskObject = createTask(taskObjectParent,conObj.Value);
taskObject.Topics_Discussed__c = '';
taskObject.Goal_of_Activity__c = '';
for(MultiSelect sltVal : avaiableTopicList){
if(sltVal.isChecked){
taskObject.Topics_Discussed__c += sltVal.Name + ';';
}
}
for(MultiSelect sltVal : avaiableGoalList){
if(sltVal.isChecked){
taskObject.Goal_of_Activity__c += sltVal.Name + ';';
}
}
tasksToBeSaved.add(taskObject);
}
}
}else{
taskObjectParent.Subject = taskObjectParent.Type;
taskObjectParent.Topics_Discussed__c = '';
taskObjectParent.Goal_of_Activity__c = '';
for(MultiSelect sltVal : avaiableTopicList){
if(sltVal.isChecked){
taskObjectParent.Topics_Discussed__c += sltVal.Name + ';';
}
}
for(MultiSelect sltVal : avaiableGoalList){
if(sltVal.isChecked){
taskObjectParent.Goal_of_Activity__c += sltVal.Name + ';';
}
}
upsert taskObjectParent;
}
System.debug('=:tasksToBeSaved:=' +tasksToBeSaved);
if(!tasksToBeSaved.isEmpty()){
upsert tasksToBeSaved;
}
//PageReference pg = new PageReference('/'+ApexPages.currentPage().getParameters().get('retURL'));
//PageReference pg = new PageReference('/'+retId);
PageReference pg = new PageReference(retId);
System.debug(' >> > > > 342 = = = '+retId);
pg.setRedirect(true);
return pg;
// return null;
}
}catch(Exception e){
System.debug(e);
return null;
}
//return null;
}
private Task createTask(Task taskObjectParent1,String contactIdStr){
Task taskObject = new Task();
if((taskObjectParent.Type == 'Physician-to-Physician Visit' && inputValue != 'Physician-to-Physician Visit') || (taskObjectParent.Type == 'Sports Medicine Visit' && inputValue != 'Sports Medicine Visit') || (taskObjectParent.Type == 'Sports Medicine Phone Call' && inputValue != 'Sports Medicine Phone Call')){
}else{
taskObject.Id = taskObjectParent1.Id;
}
taskObject.Type = taskObjectParent1.Type;
//taskObject.Subject = taskObjectParent1.Type;
taskObject.whatId = taskObjectParent1.whatId;
taskObject.whoId = contactIdStr;
taskObject.OwnerId = taskObjectParent1.OwnerId;
taskObject.Description = taskObjectParent1.Description;
taskObject.ActivityDate = taskObjectParent1.ActivityDate;
taskObject.Status = taskObjectParent1.Status;
taskObject.Priority = taskObjectParent1.Priority;
taskObject.Goal_of_Activity__c = taskObjectParent1.Goal_of_Activity__c;
taskObject.Topics_Discussed__c = taskObjectParent1.Topics_Discussed__c;
taskObject.Visit_Duration__c = taskObjectParent1.Visit_Duration__c;
taskObject.Activity_Cost__c = taskObjectParent1.Activity_Cost__c;
return taskObject;
}
//Wrapper class
public class MultiSelect{
public boolean isChecked{get;set;}
public String Name{get;set;}
public Id Value{get;set;}
public String isDisplay{get;set;}
public MultiSelect(boolean isChecked, String Name, Id Value){
this.isChecked = isChecked;
this.Name = Name;
this.Value = Value;
this.isDisplay = '';
}
}
}```
Visualforce page -
<apex:page standardController="Task" id="thePageId" extensions="Sim_NewTaskController" tabStyle="Task" action="{!loadNewTask}">
<head>
<meta name="viewport" content="width=320; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;" />
</head>
<apex:includeScript value="/soap/ajax/32.0/apex.js"/>
<apex:outPutPanel id="myMSG">
<apex:pageMessages id="msg" />
</apex:outPutPanel>
<script>
function setFocusOnLoad() {}
function toggleComponent(taskType,componentToToggle,taskId){
console.log('taskId : '+taskId);
//filterFields();
if(taskId == 'NULL' || taskId == ''){
var contactComponent = document.getElementsByClassName(componentToToggle)[0];
var selectedValue = taskType.value;
console.log(componentToToggle);
if(selectedValue == 'Physician-to-Physician Visit' || selectedValue == 'Unsuccessful Physician-to-Physician Visit' || selectedValue == 'Sports Medicine Visit' || selectedValue == 'Sports Medicine Phone Call'){
contactComponent.style.display ='block';
}else{
contactComponent.style.display ='none';
}
}else{
var contactComponent = document.getElementsByClassName(componentToToggle)[0];
var selectedValue = taskType.value;
console.log(componentToToggle);
var oldTaskType = String(document.getElementById('thePageId:newTaskPage:theHiddenInput').value);
if((oldTaskType != 'Physician-to-Physician Visit' && selectedValue == 'Physician-to-Physician Visit') || (oldTaskType != 'Sports Medicine Visit' && selectedValue == 'Sports Medicine Visit') || (oldTaskType != 'Sports Medicine Phone Call' && selectedValue == 'Sports Medicine Phone Call') ){
contactComponent.style.display ='block';
}else{
contactComponent.style.display ='none';
}
}
//alert(taskType.value);
filterFields(taskType.value);
}
function filterContactList(searchVal){
var y = document.getElementsByClassName("contactRow");
for (i = 0; i < y.length; i++) {
var title = y[i].title.toUpperCase();
if(title.search(searchVal.toUpperCase()) == 0){
y[i].style.display = '';
}else if(title.search(searchVal) == -1){
y[i].style.display = 'none';
}
}
}
</script>
<style>
<!-- .multilist{
float:left;
vertical-align:middle
}
.multilist p {
padding: 0;
text-align: center;
white-space: normal;
width: 50px;
margin:0;
}
.multilist .btn{
margin-top:3px;
margin-left:10px;
margin-right:10px;
}
.label{
width:100%;
font-weight:bold;
float:left;
}
.relatedToSection{
float:left;
padding-left:13.5%;
}-->
.searchTextBox::placeholder {
font-style:italic;
font-weight: bold;
text-shadow: 0.5px 0px 0.5px #000000;
opacity: 1;
}
.lookupInput {
position: relative;
}
.lookupInput a, .lookupInput a:hover, .lookupInput a:focus {
position: absolute;
width: 30px !important;
height: 30px !important;
right: 0;
top: -1px;
border: 0 !important;
background: transparent !important;
padding: 0 !important;
outline: none !important;
box-shadow: none !important;
}
.custom-tooltip .slds-popover {
display: none;
}
.custom-tooltip a:hover+.slds-popover {
display: block;
}
#media (min-width:767px){
select[multiple] {
min-height: 101px !important;
}
}
</style>
<!-- immediate="true" -->
<apex:slds />
<apex:form id="newTaskPage">
<apex:actionFunction action="{!filterFields}" name="filterFields" reRender="myMSG,taskInfo" >
<apex:param value="" name="tType" />
</apex:actionFunction>
<apex:sectionHeader title="Task" subtitle="New Task"/>
<apex:inputHidden value="{!inputValue}" id="theHiddenInput"/>
<div class="slds-card">
<div class="slds-card__header slds-grid slds-border_bottom slds-p-bottom_small" style="background-color: #fafaf9;">
<div class="slds-media slds-media_center slds-has-flexi-truncate">
<div class="slds-media__body">
<h2 class="slds-card__header-title slds-text-heading_small">
Task Edit
</h2>
</div>
<div class="slds-no-flex">
<apex:commandButton action="{!performSave}" title="Save" value="Save" styleClass="slds-button slds-button_brand"/>
<apex:commandButton action="{!cancel}" title="Cancel" value="Cancel" styleClass="slds-button slds-button_neutral"/>
</div>
</div>
</div>
<div class="slds-card__body slds-p-horizontal_small">
<div class="slds-m-bottom_small slds-p-around_xx-small" style="background-color: #fafaf9;"><strong>Related To</strong></div>
<div class="slds-form slds-form_horizontal">
<div>
<div style="max-width: 600px;">
<apex:outputPanel styleClass="relatedToSection">
<div class="slds-form-element">
<apex:outputLabel value="Account" styleClass="slds-form-element__label"/>
<div class="slds-form-element__control slds-m-top_xxx-small">
<apex:outputField value="{!taskObjectParent.WhatId}" title="This will contain Related Account" label="Account" />
</div>
</div>
<!--apex:outputPanel ></apex:outputPanel-->
<!-- rendered="{!IF((taskObjectParent.Id = null),true,false)}" -->
<apex:outputPanel style="display:none" styleclass="taskContactMultiList" id="contactPenal" >
<apex:inputText styleClass="searchTextBox" value="{!searchText}" onkeyup="filterContactList(this.value);"
style="box-shadow: -10px -2px 25px -8px rgba(158,150,158,1);background-color:#f2f2ff;font-weight: bold;font-size:100%;padding: 5px; color: black; width: 314px;height: 20px;margin-left: 33%;margin-bottom: 1px;" html-placeholder="Select Contacts" >
</apex:inputText>
<div class="slds-form-element">
<apex:outputLabel value="Select Contact to create task" styleClass="slds-form-element__label" id="con12"/>
<div class="slds-form-element__control" style="padding-right: 82px;">
<div class="slds-scrollable_y slds-m-top_x-small slds-m-bottom_small slds-p-around_x-small" style="max-height: 90px; border: 1px solid #dddbda; border-radius: .25rem;">
<table>
<apex:repeat value="{!avaiableContactlList}" var="con" id="myTable">
<tr class="contactRow" title="{!con.Name}">
<td width="20" class="slds-p-bottom_x-small">
<span class="slds-checkbox slds-checkbox_standalone">
<apex:inputCheckbox value="{!con.isChecked}" onclick="selectAllCheckboxes('contactCheckBoxId')" id="contactCheckBoxId"/>
<span class="slds-checkbox_faux"></span>
</span>
</td>
<td class="slds-p-bottom_x-small">
<label >
{!con.Name}
</label>
</td>
</tr>
</apex:repeat>
</table>
</div>
Total Number of Selected record :<span style="font-weight:bold" id="selContactSize">0</span>
</div>
</div>
</apex:outputPanel>
<div class="slds-form-element">
<apex:outputLabel value="Contact" styleClass="slds-form-element__label" rendered="{!IF((taskObjectParent.Id != null),IF(taskObjectParent.whoId == null,false,true),false)}"/>
<div class="slds-form-element__control">
<apex:outputField value="{!taskObjectParent.whoId}" title="this will contain related contact" label="Contact" rendered="{!IF((taskObjectParent.Id != null),IF(taskObjectParent.whoId == null,false,true),false)}"/>
</div>
</div>
</apex:outputPanel>
</div>
<div class="slds-m-bottom_small slds-p-around_xx-small" style="background-color: #fafaf9;"><strong>Task Information</strong></div>
<div id="taskInfo" style="max-width: 600px;">
<div class="slds-form-element">
<apex:outputLabel value="Activity Objective" styleClass="slds-form-element__label"/>
<div class="slds-form-element__control">
<apex:inputField value="{!taskObjectParent.Type}" required="true" onchange="toggleComponent(this,'taskContactMultiList','{!taskObjectParent.Type}');onChangeActMethod()" styleClass="slds-select" Id="st" >
</apex:inputField>
<apex:actionFunction name="onChangeActMethod" action="{!filterFields}" rerender="refreshing"/>
</div>
</div>
<div class="slds-form-element">
<apex:outputLabel value="Goal of Activity" styleClass="slds-form-element__label"/>
<div class="slds-form-element__control" style="padding-right: 82px;">
<div class="slds-scrollable_y slds-m-top_x-small slds-m-bottom_small slds-p-around_x-small" style="max-height: 90px; border: 1px solid #dddbda; border-radius: .25rem;">
<table>
<apex:repeat value="{!avaiableGoalList}" var="goal" >
<tr>
<td width="20" class="slds-p-bottom_x-small">
<span class="slds-checkbox slds-checkbox_standalone">
<apex:inputCheckbox onclick="selectAllCheckboxes('goalCheckBoxId')" value="{!goal.isChecked}" id="goalCheckBoxId"/>
<span class="slds-checkbox_faux"></span>
</span>
</td>
<td class="slds-p-bottom_x-small">
<label>
{!goal.Name}
</label>
</td>
</tr>
</apex:repeat>
</table>
</div>
Total Number of Selected record :<span style="font-weight:bold" id="setGoalsLength">{!totalAvaiableGoal}</span>
</div>
</div>
<div class="slds-form-element">
<apex:outputLabel value="Due Date" styleClass="slds-form-element__label"/>
<div class="slds-form-element__control" style="padding-right: 82px;">
<apex:inputField required="true" value="{!taskObjectParent.ActivityDate}" styleClass="slds-input"/>
</div>
</div>
<div class="slds-form-element">
<apex:outputLabel value="Priority" styleClass="slds-form-element__label"/>
<div class="slds-form-element__control">
<apex:inputField value="{!taskObjectParent.Priority}" styleClass="slds-select"/>
</div>
</div>
<div class="slds-form-element">
<apex:outputLabel value="Status" styleClass="slds-form-element__label"/>
<div class="slds-form-element__control">
<apex:inputField value="{!taskObjectParent.Status}" styleClass="slds-select"/>
</div>
</div>
<div class="slds-form-element">
<label class="slds-form-element__label">Activity Cost
<span class="custom-tooltip" style="position: relative;" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<a href="javascript:void(0)" aria-describedby="help">
<span class="slds-icon_container slds-icon-utility-info">
<svg class="slds-icon slds-icon slds-icon_xx-small slds-icon-text-default" aria-hidden="true">
<use xlink:href="{!URLFOR($Asset.SLDS, '/assets/icons/utility-sprite/svg/symbols.svg#info')}"></use>
</svg>
<span class="slds-assistive-text">Click here to learn more</span>
</span>
</a>
<div class="slds-popover slds-popover_tooltip slds-nubbin_bottom-left" role="tooltip" id="help" style="position:absolute;bottom:25px;left:-15px; width: 200px;">
<div class="slds-popover__body">
Enter the cost of any gift or other expense for the activity
</div>
</div>
</span>
</label>
<div class="slds-form-element__control">
<apex:inputField value="{!taskObjectParent.Activity_Cost__c}" styleClass="slds-input"/>
</div>
</div>
<div class="slds-form-element">
<apex:outputLabel value="Assigned To" styleClass="slds-form-element__label"/>
<div class="slds-form-element__control">
<apex:inputField value="{!taskObjectParent.OwnerId}" styleClass="slds-input"/>
</div>
</div>
<div class="slds-form-element">
<apex:outputLabel value="Visit Duration" styleClass="slds-form-element__label"/>
<div class="slds-form-element__control">
<apex:inputField value="{!taskObjectParent.Visit_Duration__c}" styleClass="slds-select" />
</div>
</div>
<div class="slds-form-element">
<apex:outputLabel value="Notes" styleClass="slds-form-element__label"/>
<div class="slds-form-element__control">
<apex:inputField value="{!taskObjectParent.Description}" styleClass="slds-textarea"/>
</div>
</div>
<div class="slds-form-element">
<apex:outputLabel value="Topics Discussed" styleClass="slds-form-element__label"/>
<apex:outputPanel id="refreshing">
<div class="slds-form-element__control" style="padding-right: 82px;">
<div class="slds-scrollable_y slds-m-top_x-small slds-m-bottom_small slds-p-around_x-small" style="max-height: 90px; border: 1px solid #dddbda; border-radius: .25rem;">
<table>
<apex:repeat value="{!avaiableTopicList}" var="topic">
<tr>
<td width="20" class="slds-p-bottom_x-small">
<span class="slds-checkbox slds-checkbox_standalone">
<apex:inputCheckbox value="{!topic.isChecked}" onclick="selectAllCheckboxes('topicCheckBoxId')" id="topicCheckBoxId"/>
<span class="slds-checkbox_faux"></span>
</span>
</td>
<td class="slds-p-bottom_x-small">
<label>
{!topic.Name}
</label>
</td>
</tr>
</apex:repeat>
</table>
</div>
Total Number of Selected record :<span style="font-weight:bold" id="selTopicSize">{!totalAvaiableTopic}</span>
</div>
</apex:outputPanel>
</div>
</div>
</div>
</div>
</div>
<div class="slds-card__footer slds-text-align_right">
<apex:commandButton action="{!performSave}" title="Save" value="Save" styleClass="slds-button slds-button_brand" />
<apex:commandButton action="{!cancel}" title="Cancel" value="Cancel" styleClass="slds-button slds-button_neutral"/>
<apex:commandButton action="{!edit}" title="Edit" value="{!URLFOR($Action.Task.Edit,recordId)}" styleClass="slds-button slds-button_neutral"/>
<!--<apex:outputLink value="{!URLFOR($Action.Task.Edit,recordId)}">Edit</apex:outputLink>-->
</div>
</div>
<script>
function selectAllCheckboxes(receivedInputID){
var inputCheckBox = document.getElementsByTagName("input");
var totalCount = 0;
for(var i=0; i<inputCheckBox.length; i++){
if(inputCheckBox[i].id.indexOf(receivedInputID)!=-1){
if(inputCheckBox[i].checked == true){
totalCount = totalCount + 1;
}
}
}
//console.log('====>' + totalCount);
if(receivedInputID=='contactCheckBoxId'){
document.getElementById('selContactSize').innerHTML = totalCount;
}else if(receivedInputID=='goalCheckBoxId'){
document.getElementById('setGoalsLength').innerHTML = totalCount;
}else if(receivedInputID=='topicCheckBoxId'){
document.getElementById('selTopicSize').innerHTML = totalCount;
}
}
/*window.onload = ()=>{
alert('hello');
}*/
//console.log({!whatId});
function navigateTo() {
//debugger;
let data = '{!whatId}';
console.log(data+'--'+text);
if((typeof sforce != 'undefined') && sforce && (sforce.one)){
// Salesforce1 navigation
sforce.one.navigateToURL('https://www.google.com');
} /*else {
// Set the window's URL using a Visualforce expression
window.location.href = location.origin + '/' + {!whatId};
// site prefix helps when navigation in community
}*/
}
</script>
</apex:form>
</apex:page>

Unknown constructor'.......(ApexPages.StandardController controller)'

Unknown constructor'.......(ApexPages.StandardController controller)'
I'm new to Salesforce.
I'm doing a practice problem in which I have to create a Visualforce page to save a contact detail and display that on another VF page.
ContactDetails.vfp :
<apex:page standardController="Contact" extensions="ContactDisplayController">
<apex:form >
<apex:pageBlock title="Add Contact">
<apex:pageBlockSection columns="1">
<apex:inputField value="{! Contact.FirstName }"/>
<apex:inputField value="{! Contact.Lastname }"/>
<apex:inputField value="{! Contact.Phone }" />
<apex:inputField value="{! Contact.Email }" />
<apex:inputField value="{! Contact.Birthdate }" />
</apex:pageBlockSection>
<apex:pageBlockButtons >
<apex:commandButton action="{!saveAndRedirect}" value="Save" />
</apex:pageBlockButtons>
</apex:pageBlock>
</apex:form>
</apex:page>
ContactDisplay.vfp :
<apex:page standardController="Contact" extensions="ContactDisplayController">
<apex:form >
<apex:pageBlock title="Display Contact">
<apex:pageBlockSection columns="1">
<apex:outputText value="{! Contact.FirstName }"/>
<apex:outputText value="{! Contact.Lastname }"/>
<apex:outputText value="{! Contact.Phone }" />
<apex:outputText value="{! Contact.Email }" />
<apex:outputText value="{! Contact.Birthdate }" />
</apex:pageBlockSection>
<apex:pageBlockButtons >
<apex:commandButton action="{!redirectToMyVF}" value="Close" />
</apex:pageBlockButtons>
</apex:pageBlock>
</apex:form>
</apex:page>
ContactDisplayController.apxc :
public class ContactDisplayController {
public Contact con { get; set; }
public ContactDisplayController(ApexPages.StandardController controller) {
}
public PageReference redirectToMyVF() {
PageReference pref = new PageReference('/apex/Page');
pref.setRedirect(true);
return pref;
}
public PageReference saveAndRedirect() {
if(controller.Save() != null) {
//save your contact record
controller.Save();
//retrieve the contact record
con = ( Contact ) controller.getRecord();
System.debug( con );
//pass the contact id as the URL parameter
PageReference redirectPage = '/ContactDisplay?id=' + con.Id;
return redirectPage;
}
return null;
}
}
When I'm trying to save this code I'm getting error :
Unknown constructor 'ContactDisplayController.ContactDisplayController(ApexPages.StandardController controller)'
Please let me know what is wrong with this code.
I don't think your apex class is saving because it should have a few errors in it and therefore your visual force pages won't be able to locate the extensions constructor.
Update your ContactDisplayController Class to the following and make sure it saves without errors first then save you visual force pages and there should be no error
public class ContactDisplayController {
public Contact con { get; set; }
public ApexPages.StandardController controller {get; set;}
public ContactDisplayController(ApexPages.StandardController controller) {
this.controller = controller;
}
public PageReference redirectToMyVF() {
PageReference pref = new PageReference('/apex/Page');
pref.setRedirect(true);
return pref;
}
public PageReference saveAndRedirect() {
if(controller.Save() != null) {
//save your contact record
controller.Save();
//retrieve the contact record
con = ( Contact ) controller.getRecord();
System.debug( con );
//pass the contact id as the URL parameter
PageReference redirectPage = new PageReference('/apex/ContactDisplay?id=' + con.Id);
return redirectPage;
}
return null;
}
}

How to pass field values to apex class by command button?

I need to pass id field value to apex class to delete that row by using command button.
Class:
public class search_delete
{
public string id {get;set;}
public list<account> acc{get;set;}
public search_delete()
{
acc = new list<account>();
acc = [SELECT id,name,phone,industry from account];
}
public void delete_record()
{
acc = [SELECT name,phone,industry from account where id = :id];
delete acc;
}
}
VP:
<apex:page controller="search_delete" >
<apex:form >
<apex:pageBlock >
<apex:pageBlockTable value="{!acc}" var="a">
<apex:column value="{!a.Name}"/>
<apex:column value="{!a.Phone}"/>
<apex:column value="{!a.Industry}"/>
<apex:column >
<apex:commandButton value="Delete" Action="{!delete_record}">
<apex:param name="accId" value="{!a.id}"/>
</apex:commandButton>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>
Now i need to pass id value to apex class from Vp page by the click of delete button.
My Output
use the assignto property of apex command button.
<apex:page controller="search_delete" >
<apex:form >
<apex:pageBlock >
<apex:pageBlockTable value="{!acc}" var="a">
<apex:column value="{!a.Name}"/>
<apex:column value="{!a.Phone}"/>
<apex:column value="{!a.Industry}"/>
<apex:column >
<apex:commandButton value="Delete" Action="{!delete_record}">
<apex:param name="accId" value="{!a.id}" assignto="{!idchosen}/>
</apex:commandButton>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
public class search_delete
{
public string id {get;set;}
public string idchosen {get;set;}
public list<account> acc{get;set;}
public search_delete()
{
acc = new list<account>();
acc = [SELECT id,name,phone,industry from account];
}
public void delete_record()
{
acc = [SELECT name,phone,industry from account where id = :idchosen];
delete acc;
}
}

dynamically add rows and maintain values on refresh

I have a VF page that I can dynamically add rows to a pageBlockTable when clicking a button "Add Participant". I have the page working where I can add the rows, but I'm losing the values in the row when I add a new row. The values get cleared.
Can anyone help on how I can maintain my values when I add new rows? I'm using a wrapper class.
Here is my page:
<apex:page standardController="Call_Report__c" extensions="CallReportControllerExtension" showHeader="true" sidebar="true">
<apex:sectionHeader title="Call Report Edit" subtitle="{!IF(isEditMode, 'New Call Report', CallReportName)}" />
<apex:includeScript value="{!URLFOR($Resource.JQueryUI, '/js/jquery-1.8.2.min.js')}" />
<apex:includeScript value="{!URLFOR($Resource.JQueryUI, '/js/jquery-ui-1.9.0.custom.js')}" />
<script type="text/javascript">
var j$ = jQuery.noConflict();
j$(document).ready(function(){
j$('.errorMsg').hide();
});
</script>
<script>
var newWin=null;
function openLookupPopup(name, id)
{
var url="/apex/ParticipantSearchPopup?namefield=" + name + "&idfield=" + id;
newWin=window.open(url, 'Popup','height=350,width=400,left=100,top=100,resizable=no,scrollbars=yes,toolbar=no,status=no');
if (window.focus)
{
newWin.focus();
}
return false;
}
function closeLookupPopup()
{
if (null!=newWin)
{
newWin.close();
}
}
</script>
<apex:form >
<apex:pageMessages id="Errors" />
<apex:pageBlock title="Call Report Edit" mode="edit">
<apex:pageBlockButtons location="both">
<apex:commandButton action="{!save}" value="Save" id="theSaveButton" />
<apex:commandButton action="{!cancel}" value="Cancel" id="theCancelButton" />
</apex:pageBlockButtons>
<apex:pageBlockSection title="Information" columns="2">
<apex:inputField value="{!Call_Report__c.Name}" required="true" />
<apex:pageBlockSectionItem rendered="{!!isEditMode}" >
<apex:outputLabel value="Owner" />
<apex:outputField value="{!Call_Report__c.Owner.Name}" />
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem rendered="{!isEditMode}" >
<apex:outputLabel value="Owner" />
<apex:outputLabel value="{!$User.FirstName} {!$User.LastName}" />
</apex:pageBlockSectionItem>
<apex:inputField value="{!Call_Report__c.Location__c}" />
<apex:inputField value="{!Call_Report__c.EventAmount__c}" />
</apex:pageBlockSection>
<apex:pageBlockSection title="Detail" columns="1">
<apex:inputTextArea value="{!Call_Report__c.Purpose__c}" cols="75" />
<apex:inputTextArea value="{!Call_Report__c.Results__c}" cols="75" />
<apex:inputTextArea value="{!Call_Report__c.Next_Steps__c}" cols="75" />
<apex:inputField value="{!Call_Report__c.Description__c}" />
</apex:pageBlockSection>
</apex:pageBlock>
<apex:pageBlock >
<apex:pageBlockButtons location="top" id="topButton">
<apex:commandButton id="newButton" value="Add Participant" action="{!addParticipant}" rerender="pageTable" immediate="true" />
</apex:pageBlockButtons>
<apex:pageBlockSection title="Participants" columns="1">
<apex:pageBlockTable id="pageTable" value="{!participantLinesForPage}" var="part">
<apex:column headerValue="Account" width="25%">
<apex:inputHidden value="{!part.participantLine.Account__r.Id}" id="targetAccountId" />
<apex:inputText value="{!part.participantLine.Account__r.Name}" id="targetAccountName" onFocus="this.blur()" disabled="false" style="width:175px;" />
<a href="#" onclick="openLookupPopup('{!$Component.targetAccountName}', '{!$Component.targetAccountId}'); return false" ><img onmouseover="this.className = 'lookupIconOn';this.className = 'lookupIconOn';" onmouseout="this.className = 'lookupIcon';this.className = 'lookupIcon';" onfocus="this.className = 'lookupIconOn';" onblur="this.className = 'lookupIcon';" class="lookupIcon" src="/s.gif" /></a>
</apex:column>
<apex:column headerValue="Contact" width="25%">
<apex:inputHidden value="{!part.participantLine.Contact__r.Id}" id="targetContactId" />
<apex:inputText value="{!part.participantLine.Contact__r.Name}" id="targetContactName" onFocus="this.blur()" disabled="false" style="width:175px;" />
<a href="#" onclick="openLookupPopup('{!$Component.targetContactName}', '{!$Component.targetContactId}'); return false" ><img onmouseover="this.className = 'lookupIconOn';this.className = 'lookupIconOn';" onmouseout="this.className = 'lookupIcon';this.className = 'lookupIcon';" onfocus="this.className = 'lookupIconOn';" onblur="this.className = 'lookupIcon';" class="lookupIcon" src="/s.gif" /></a>
</apex:column>
<apex:column headerValue="User" width="25%">
<apex:inputHidden value="{!part.participantLine.User__r.Id}" id="targetUserId" />
<apex:inputText value="{!part.participantLine.User__r.Name}" id="targetUserName" onFocus="this.blur()" disabled="false" style="width:175px;" />
<a href="#" onclick="openLookupPopup('{!$Component.targetUserName}', '{!$Component.targetUserId}'); return false" ><img onmouseover="this.className = 'lookupIconOn';this.className = 'lookupIconOn';" onmouseout="this.className = 'lookupIcon';this.className = 'lookupIcon';" onfocus="this.className = 'lookupIconOn';" onblur="this.className = 'lookupIcon';" class="lookupIcon" src="/s.gif" /></a>
</apex:column>
<apex:column headerValue="Spent Amount" width="25%">
<apex:inputField value="{!part.participantLine.Spent_Amount__c}" />
</apex:column>
</apex:pageBlockTable>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
Here is my controller:
public with sharing class CallReportControllerExtension {
private final Call_Report__c callReport;
public Boolean isEditMode {get; set;}
public List<Participants> participantLinesForPage {get; set;}
public CallReportControllerExtension(ApexPages.StandardController stdController) {
this.callReport = (Call_Report__c)stdController.getRecord();
isEditMode = isEditPage(ApexPages.currentPage().getParameters().get('save_new'));
refreshLineItems();
}
public String getCallReportName() {
return [select Name from Call_Report__c where Id =: callReport.Id].Name;
}
public PageReference addParticipant() {
Participant__c newRecord = new Participant__c();
//newRecord.Account__c = '001f0000007qcD5';
//newRecord.Contact__c = '003f0000007H61z';
//newRecord.User__c = '005f0000000U5ME';
//newRecord.Spent_Amount__c = 100.00;
participantLinesForPage.add(new Participants(participantLinesForPage.size(), newRecord));
return null;
}
private void refreshLineItems() {
List<Participant__c> lineItems = [select Account__c, Account__r.Id, Account__r.Name, Contact__c, Contact__r.Id, Contact__r.Name, User__c, User__r.Id, User__r.Name, Spent_Amount__c from Participant__c where Call_Report__c =: callReport.Id];
participantLinesForPage = new List<Participants>();
Integer iterate = 0;
for(Participant__c p : lineItems) {
participantLinesForPage.add(new Participants(iterate, p));
iterate += 1;
}
}
private Boolean isEditPage(String param) {
Boolean retval = false;
if(param != null) {
retval = true;
}
return retval;
}
class Participants {
public Integer iterate {get; set;}
public Participant__c participantLine {get; set;}
public Participants(Integer iterate, Participant__c participantLine) {
this.iterate = iterate;
this.participantLine = participantLine;
}
}
}
The data won't be saved until the save button is clicked, which I haven't implemented yet. I'm just trying to get the values to maintain their state when new rows are added. The refreshLineItems method is clearning the values, but I need that method when records already exist. So, my question is how do I maintain the values in the rows that haven't been saved to the database yet? I was trying to handle it in my wrapper class, but haven't been successful.
Any help is greatly appreciated!
Thanks.
Hi you losing values becouse immediate="true" tag in apex:commandButton.
You can use and "required=false" in inputField instead.

a more efficient way to get record status counts

I have a visualforce page with pagination using the standardSetController. On the page, I've also added filtering by status...i.e. new, working, closed, etc. Right now, I'm doing a count() for each status value to display the status count on the page, but that requires a query for each status, which is inefficient. I'd like to get the status counts in a more efficient way.
Here is my controller:
public with sharing class myController {
public ApexPages.StandardSetController setCtrl{get; set;}
public String projId { get; set; }
public String clientName { get; set; }
private List<Ticket__c> TicketList = new List<Ticket__c>();
public myController()
{
projId = ApexPages.currentPage().getParameters().get('id');
clientName = [Select Client__r.Name From Project__c Where Id =: projId].Client__r.Name;
setCtrl = new ApexPages.StandardSetController(Database.getQueryLocator([select Ticket_Number__c, Name, Status__c, Description__c, Description_of_Resolution__c, CreatedDate from Ticket__c Where Project__c =: projId ORDER BY CreatedDate DESC]));
ticketList = (List<Ticket__c>)setCtrl.getRecords();
setCtrl.setPageSize(5);
}
public Integer getNewStatusCount() {
return [select count() from Ticket__c Where Project__c =: projId and status__c = 'New'];
}
public Integer getWorkingStatusCount() {
return [select count() from Ticket__c Where Project__c =: projId and status__c = 'Working'];
}
public Integer getResolvedStatusCount() {
return [select count() from Ticket__c Where Project__c =: projId and status__c = 'Resolved'];
}
public Integer getClosedStatusCount() {
return [select count() from Ticket__c Where Project__c =: projId and status__c = 'Closed'];
}
public Integer getCancelledStatusCount() {
return [select count() from Ticket__c Where Project__c =: projId and status__c = 'Cancelled'];
}
public Integer getReopenedStatusCount() {
return [select count() from Ticket__c Where Project__c =: projId and status__c = 'Reopened'];
}
public Boolean hasNext {
get {
return setCtrl.getHasNext();
}
}
public Boolean hasPrevious {
get {
return setCtrl.getHasPrevious();
}
set;
}
public Integer pageNumber {
get {
return setCtrl.getPageNumber();
}
set;
}
public Integer totalPages {
get {
totalPages = math.ceil((Double)setCtrl.getResultSize() / setCtrl.getPageSize()).intValue();
return totalPages;
}
set;
}
public void first() {
setCtrl.first();
}
public void last() {
setCtrl.last();
}
public void previous() {
setCtrl.previous();
}
public void next() {
setCtrl.next();
}
public List<Ticket__c> getTickets()
{
return (List<Ticket__c>)setCtrl.getRecords();
}
public void filterStatus() {
string myParam = apexpages.currentpage().getparameters().get('myParam');
setCtrl = new ApexPages.StandardSetController(Database.getQueryLocator([select Ticket_Number__c, Name, Status__c, Description__c, Description_of_Resolution__c, CreatedDate from Ticket__c Where Project__c =: projId AND Status__c =: myParam ORDER BY CreatedDate DESC]));
setCtrl.setPageSize(5);
}
}
Here is the VF code:
<div class="contact-form">
<apex:outputPanel id="contactForm">
<apex:form >
<ul class="filteredView">
<li>
<apex:outputLink value="/tickets?id={!projId}">View All</apex:outputLink>
</li>
<li>
({!NewStatusCount})
<apex:commandLink action="{!filterStatus}" value=" New" rerender="contactForm">
<apex:param name="myParam" value="New"/>
</apex:commandLink>
</li>
<li>
({!WorkingStatusCount})
<apex:commandLink action="{!filterStatus}" value=" Working" rerender="contactForm">
<apex:param name="myParam" value="Working"/>
</apex:commandLink>
</li>
<li>
({!ResolvedStatusCount})
<apex:commandLink action="{!filterStatus}" value=" Resolved" rerender="contactForm">
<apex:param name="myParam" value="Resolved"/>
</apex:commandLink>
</li>
<li>
({!ClosedStatusCount})
<apex:commandLink action="{!filterStatus}" value=" Closed" rerender="contactForm">
<apex:param name="myParam" value="Closed"/>
</apex:commandLink>
</li>
<li>
({!CancelledStatusCount})
<apex:commandLink action="{!filterStatus}" value=" Cancelled" rerender="contactForm">
<apex:param name="myParam" value="Cancelled"/>
</apex:commandLink>
</li>
<li id="last">
({!ReopenedStatusCount})
<apex:commandLink action="{!filterStatus}" value=" Reopened" rerender="contactForm">
<apex:param name="myParam" value="Reopened"/>
</apex:commandLink>
</li>
</ul>
<h5>
TICKETS
</h5>
<table width="95%" border="1" cellpadding="5">
<tr align="left">
<th style="width:25px;">Ticket#</th>
<th style="width:200px;">Subject</th>
<th>Description</th>
<th style="width:50px;">Status</th>
<th style="width:75px;"></th>
</tr>
<apex:repeat value="{!tickets}" var="ticket">
<tr>
<td>{!ticket.Ticket_Number__c}</td>
<td>{!ticket.Name}</td>
<td>{!ticket.Description__c}</td>
<td>{!ticket.Status__c}</td>
<td><apex:outputLink value="/detail?id={!projId}&ticketId={!ticket.Id}">View Details</apex:outputLink></td>
</tr>
</apex:repeat>
</table>
<apex:outputPanel rendered="{!(tickets.empty == false)}" styleClass="pagination" >
<ul>
<li><apex:commandLink id="first" value="First" action="{!first}" rendered="{!hasPrevious}" /></li>
<li><apex:commandLink id="prev" value="Prev" action="{!previous}" rendered="{!hasPrevious}" /></li>
<li><apex:commandLink id="next" value="Next" action="{!next}" rendered="{!hasNext}" /></li>
<li><apex:commandLink id="last" value="Last" action="{!last}" rendered="{!hasNext}" /></li>
<li><apex:outputText value="Page {!pageNumber} of {!totalPages}" /></li>
</ul>
</apex:outputPanel>
</apex:form>
</apex:outputPanel>
</div>
</div>
Thanks.
You can get the count of each status for all the status's in a single SOQL query
[select status__c, count(id) from Ticket__c Where Project__c =: projId group by status__c]
You could then expose the results through your existing getter, expose the query results and bind them to the UI via a repeater.

Resources