Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public with sharing class SearchController{
- public integer PageSize {get;set;}
- public integer PageNumber {get;set;}
- public integer RecordCount {get;set;}
- public List<contactwrapper> objAWList {get;set;}
- private Set<id> selectedContactIds;
- public boolean displayPopup {get; set;}
- public List<contact> objSelectedContacts {get; set;}
- private String soql {get;set;}
- public SearchController() {
- PageSize = 10;
- PageNumber = 1;
- RecordCount = 0;
- selectedContactIds = new Set<id>();
- objAWList = new List<contactwrapper>();
- objSelectedContacts = new List<contact>();
- }
- public void closePopup() {
- displayPopup = false;
- }
- public void showPopup() {
- setSelectedContacts();
- displayPopup = true;
- objSelectedContacts = GetSelectedcontacts();
- }
- public Integer getSelectedCount(){
- return this.selectedContactIds.size();
- }
- public List<contact> GetSelectedContacts(){
- List<contact> objConList = [Select Id, Name,Email,Account.Name,Account_Cust__c,Job_Title__c
- From Contact Where ID IN : selectedContactIds];
- system.debug('objConList :'+objConList);
- return objConList;
- }
- private void setSelectedContacts()
- {
- for(contactwrapper item: objAWList)
- {
- if(item.IsSelected)
- {
- if(!this.selectedContactIds.contains(item.ContactId))
- {
- this.selectedContactIds.add(item.ContactId);
- }
- }
- else
- {
- if(this.selectedContactIds.contains(item.ContactId))
- {
- this.selectedContactIds.remove(item.ContactId);
- }
- }
- }
- }
- public integer PageIndex {
- get { return (PageNumber - 1); }
- }
- public integer PageCount {
- get { return getPageCount(); }
- }
- public integer Offset {
- get { return (PageSize * PageIndex); }
- }
- public void runSearch() {
- objAWList = new List<contactwrapper>();
- try {
- List<Contact> objConList = new List<Contact>();
- String contactName = Apexpages.currentPage().getParameters().get('ContactName');
- if (!contactName.equals('')){
- soql = 'select firstname, lastname, Name,account.name,Job_Title__c,Account_Cust__c from contact where account.name != null';
- soql += ' and name LIKE '%' + contactName + '%'';
- soql += ' order by firstName ASC limit '+PageSize +' offset '+Offset;
- system.debug('soqlfinal::'+soql);
- objConList = Database.query(soql);
- RecordCount = objConList.size();
- }else if(contactName.equals('')){
- RecordCount = objConList.size();
- objConList.clear();
- }
- system.debug('objConList---'+objConList);
- if(!objConList.isEmpty()){
- for(Contact Con : objConList){
- ContactWrapper objAW = new ContactWrapper();
- objAW.ContactId = Con.Id;
- objAW.ContactName = Con.Name;
- objAW.AccountCust= Con.Account_Cust__c ;
- objAW.JobTitle= Con.Job_Title__c;
- if(this.selectedContactIds.contains(con.Id)){
- objAW.IsSelected = true;
- }
- else{
- objAW.IsSelected = false;
- }
- objAWList.Add(objAW);
- }
- }
- }
- catch (QueryException e) {
- ApexPages.addMessages(e);
- }
- }
- public integer LNumber {
- get { return RecordCount == 0 ? 0 : (Offset + 1); }
- }
- public integer UNumber {
- get {
- integer iUNum = ((LNumber + PageSize) - 1);
- return (iUnum > RecordCount) ? RecordCount : iUNum;
- }
- }
- public boolean AllowMoveNext {
- get{ return ((PageIndex + 1) < PageCount); } } public boolean AllowMovePrev { get{ return (PageIndex > 0); }
- }
- public void Prev() {
- setSelectedContacts();
- PageNumber--;
- if (PageNumber <= 0) { PageNumber = 1; } } public void Next() { setSelectedContacts(); PageNumber++; if (PageNumber > PageCount) {
- PageNumber = PageCount;
- }
- }
- public void Last() {
- setSelectedContacts();
- PageNumber = PageCount;
- }
- public void First() {
- setSelectedContacts();
- PageNumber = 1;
- }
- private integer getPageCount() {
- integer iPageCount = 1;
- if (RecordCount != 0 && PageSize != 0) {
- iPageCount = (RecordCount/PageSize) + ((Math.mod(RecordCount, PageSize)) > 0 ? 1 : 0);
- }
- return iPageCount;
- }
- public class Contactwrapper
- {
- public Id ContactId {get;set;}
- public String ContactName {get;set;}
- public String AccountCust {get;set;}
- public String JobTitle {get;set;}
- public Boolean IsSelected{get;set;}
- public Contactwrapper()
- {
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement