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

Wrapper Class with StandardSetController... Please help

Hi,

 

I have written one controller extension for search one custom object records along with pagination using StandardSet Controller. I have created one wrapper class also to select some of the records from search result. The problem is either of 2 functionality is working. Either search function OR selecting the records and performing action on selected record is working but not both the functionality is working at same time..

 

Does any one else faceed same problem? Please help me

 

My apex code and VF code is below:

public with sharing class SMSController {
public Integer size = 20;
public Integer totalPageNo;
public Search__c condition = new Search__c();
public SMS_Template__c SmsTemplte = new SMS_Template__c();
public String qry = 'SELECT LastName,AccountId,Customer_Mobile_No__c,Birthdate,RecordTypeName__c, NotCorpRecordType__c FROM Contact WHERE NotCorpRecordType__c = 1 LIMIT 500';
private final SMS__c smsObj {get;set;}
public List<SMS__c> smsObjList = new List<SMS__c>();
public String SenderName {get;set;}
public String SenderMobile {get;set;}
//Collection of the class/wrapper objects cContact
public List<cContact> contactList {get;set;}

public SMSController(ApexPages.StandardController controller){
this.smsObj = (SMS__c)controller.getRecord();
}

public List<cContact> getContacts() {

if(contactList == null){
contactList = new List<cContact>();
for(Contact c : (list<Contact>)contct.getRecords()) {
contactList.add(new cContact(c));
}
}
return contactList;
}
public PageReference processSelected() {
List<Contact> selectedContacts = new List<Contact>();


for(cContact cCon : getContacts()){
if(cCon.selected == true){
selectedContacts.add(cCon.con);
System.debug('+++++++++++++++++++++++++++++++++'+selectedContacts.size());
}
}




for(Contact con : selectedContacts){
SMS__c smsInstance = new SMS__c();
smsInstance.Field_1__c = con.LastName;
smsInstance.Field_2__c = con.RecordTypeName__c;
smsInstance.Account__c = con.AccountId;
smsInstance.Sender_Name__c = smsObj.Sender_Name__c;
smsInstance.Sender_Phone__c = smsObj.Sender_Phone__c;
smsInstance.SMS_Template__c = smsObj.SMS_Template__c;
smsObjList.add(smsInstance);

}


if(smsObjList != null && smsObjList.size() > 0){
insert smsObjList;
}
return null;
}


public PageReference reset() {
PageReference newpage = new PageReference(System.currentPageReference().getURL());
newpage.setRedirect(true);
return newpage;
}

public ApexPages.StandardSetController contct {

get {
if(contct == null){

contct= new ApexPages.StandardSetController(Database.getQueryLocator(qry));
contct.setPageSize(size);}
return contct;
}
set;
}


public void queryContracts(){
qry = 'SELECT LastName,Customer_Mobile_No__c,Birthdate,RecordTypeName__c,AccountId FROM Contact WHERE NotCorpRecordType__c = 1 ';
qry = qry + getWhereClause() + ' LIMIT 500';
System.debug('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%'+qry);

try{
contct = new ApexPages.StandardSetController(Database.getQueryLocator(qry));
contct.setPageSize(size);


}catch(Exception e){
ApexPages.addMessages(e);
}
}
public void search(){
queryContracts();

}


public String getWhereClause(){
String whereClause = 'AND LastName != null ';

if(condition.Last_Name__c != '' && condition.Last_Name__c != null){
whereClause +='AND LastName LIKE \''+ String.escapeSingleQuotes(condition.Last_Name__c) +'%\' ';
}
if(condition.Mobile__c != '' && condition.Mobile__c != null){
whereClause +='AND Customer_Mobile_No__c LIKE \''+String.escapeSingleQuotes(condition.Mobile__c) +'%\' ';
}
if(condition.Customer_Type__c != '' && condition.Customer_Type__c != null && condition.Customer_Type__c == 'Corporate Contact'){
whereClause +='AND RecordTypeName__c LIKE \''+String.escapeSingleQuotes(condition.Customer_Type__c) +'%\' ';
}
if(condition.Customer_Type__c != '' && condition.Customer_Type__c != null && condition.Customer_Type__c == 'Individual Customer'){
whereClause +='AND IsPersonAccount = true ';
}
if(condition.Birthday_Range__c != '' && condition.Birthday_Range__c != null && condition.Birthday_Range__c == 'This Month'){
whereClause +='AND Birthdate = THIS_MONTH';
}
if(condition.Birthday_Range__c != '' && condition.Birthday_Range__c != null && condition.Birthday_Range__c == 'This Week'){
whereClause +='AND Birthdate = THIS_WEEK';
}
if(condition.Birthday_Range__c != '' && condition.Birthday_Range__c != null && condition.Birthday_Range__c == 'Today'){

whereClause +='AND Birthdate = TODAY';
}
System.debug('@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@'+whereClause);
return whereClause;
}

public Search__c getCondition(){
return this.condition;
}
public void setCondition(Search__c val){
this.condition = val;
}
public SMS_Template__c getSmsTemplte(){
return this.SmsTemplte;
}
public void setSmsTemplte(SMS_Template__c val){
this.SmsTemplte = val;
}

public SMS__c getsmsObj(){
return this.smsObj;
}

public class cContact {
public Contact con {get; set;}
public SMS__c smsObject {get;set;}
public Boolean selected {get; set;}

public cContact(Contact c) {
con = c;
selected = false;

}

public cContact (SMS__c s){
smsObject = s;
}
}

public void first() {
contct.first();
}

// returns the last page of records
public void last() {
contct.last();
}
public void previous() {
contct.previous();
}

// returns the next page of records
public void next() {
contct.next();
}

public Boolean hasNext {
get {
return contct.getHasNext();
}
set;
}

// indicates whether there are more records before the current page set.
public Boolean hasPrevious {
get {
return contct.getHasPrevious();
}
set;
}
///calculate page number and total number of records fetched by SOQL
public Integer pageNumber {
get {
return contct.getPageNumber();
}
set;
}
public Integer count {
get {
return contct.getResultSize();
}
set;
}
//Sorting of data in columns
public integer getSize() {
return size;
}

public void setSize(integer size) {
this.size = size;
}

public Integer getTotalPageNo() {
totalPageNo = contct.getResultSize()/ size;
Integer mod = contactList.size() - (totalPageNo * size);

if(mod > 0){
totalPageNo++;
}

return totalPageNo;
}
}

 

<apex:page standardController="SMS__c" id="pages" tabStyle="SMS__c" extensions="SMSController">
<apex:form id="form">
<table width="100%" border="0">
<tr>
<td width="100%">
<apex:sectionHeader title="Search Customers"/>
<apex:pageBlock id="block">

<apex:actionFunction name="searchServer" action="{!queryContracts}">
<apex:param name="firstParam" assignTo="{!PicklistSize}" value=""/>
</apex:actionFunction>

<apex:pageBlockSection collapsible="true" title="Customer Information">
<apex:inputField value="{!condition.Last_Name__c}"/>
<apex:inputField value="{!condition.Birthday_Range__c}"/>
<apex:inputField value="{!condition.Mobile__c}"/>
<apex:inputField value="{!condition.Customer_Type__c}"/>

</apex:pageBlockSection>

<apex:pageBlockSection collapsible="true" title="SMS Section">
<apex:inputField value="{!smsObj.SMS_Template__c}" required="true"/>

</apex:pageBlockSection><br/>

<apex:pageBlockSection collapsible="true" title="Sender Information. Please Enter value" columns="2">
<apex:inputField value="{!smsObj.Sender_Name__c}" id="name"/>
<apex:inputField value="{!smsObj.Sender_Phone__c}" id="mobile"/>
</apex:pageBlockSection><br/>

<apex:commandButton value="Search" action="{!search}" /> &nbsp;&nbsp;
<apex:commandButton value="Reset" action="{!reset}"/> &nbsp;&nbsp;
<apex:commandButton value="Send SMS" action="{!processSelected}"/> &nbsp;&nbsp;

Number of Records Per Page &nbsp;: &nbsp;
<apex:selectList id="PicklistSize" value="{!size}" onchange="
var pagesize = document.getElementById('{!$Component.pages:form:block:PicklistSize}').value;
searchServer(pagesize);" size="1">
<apex:selectOption itemValue="20" itemLabel="20"/>
<apex:selectOption itemValue="30" itemLabel="30"/>
<apex:selectOption itemValue="40" itemLabel="40"/>
<apex:selectOption itemValue="50" itemLabel="50"/>
</apex:selectList>
</apex:pageBlock>
</td>
</tr>
<tr>
<td>
<apex:pageBlock id="block1">
<apex:pageBlockSection title="Customer Seach - {!pageNumber} / {!totalPageNo} Pages" collapsible="true" />
<apex:panelGrid columns="6">
<apex:commandLink action="{!first}" value="<<First" rerender="block1"></apex:commandlink>...
<apex:commandLink action="{!previous}" rendered="{!hasPrevious}" value="<Previous" rerender="block1"></apex:commandlink>
<apex:commandLink action="{!next}" rendered="{!hasNext}" value="Next>" rerender="block1"></apex:commandlink>...
<apex:commandLink action="{!last}" value="Last>>" rerender="block1"></apex:commandlink>
</apex:panelGrid>
<apex:pageBlockTable width="100%" value="{!Contacts}" var="c" rendered="{!NOT(ISNULL(Contacts))}" frame="below" id="table">
<apex:column width="5%">
<!-- This is our selected Boolean property in our wrapper class -->
<apex:inputCheckbox value="{!c.selected}"/>

</apex:column>
<apex:column width="14.28%" headerValue="Customer Name">
<a href="/{!c.con.Id}">
<apex:outputField value="{!c.con.LastName}"/></a>
</apex:column>
<apex:column width="14.28%" value="{!c.con.Customer_Mobile_No__c}" headerValue="Mobile Number"/>
<apex:column width="14.28%" value="{!c.con.Birthdate}" headerValue="Birth Date"/>
<apex:column width="14.28%" value="{!c.con.RecordTypeName__c}" headerValue="Customer Type"/>

</apex:pageBlockTable>
</apex:pageBlock>
</td>
</tr>
</table>
</apex:form>

</apex:page>