Advertisement
Guest User

Untitled

a guest
Jan 24th, 2017
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.87 KB | None | 0 0
  1. public with sharing class SearchController{
  2.  
  3. public integer PageSize {get;set;}
  4. public integer PageNumber {get;set;}
  5. public integer RecordCount {get;set;}
  6. public List<contactwrapper> objAWList {get;set;}
  7. private Set<id> selectedContactIds;
  8. public boolean displayPopup {get; set;}
  9. public List<contact> objSelectedContacts {get; set;}
  10. private String soql {get;set;}
  11.  
  12. public SearchController() {
  13. PageSize = 10;
  14. PageNumber = 1;
  15. RecordCount = 0;
  16. selectedContactIds = new Set<id>();
  17. objAWList = new List<contactwrapper>();
  18. objSelectedContacts = new List<contact>();
  19.  
  20. }
  21.  
  22.  
  23. public void closePopup() {
  24. displayPopup = false;
  25. }
  26.  
  27.  
  28. public void showPopup() {
  29. setSelectedContacts();
  30. displayPopup = true;
  31. objSelectedContacts = GetSelectedcontacts();
  32. }
  33.  
  34. public Integer getSelectedCount(){
  35. return this.selectedContactIds.size();
  36. }
  37.  
  38. public List<contact> GetSelectedContacts(){
  39. List<contact> objConList = [Select Id, Name,Email,Account.Name,Account_Cust__c,Job_Title__c
  40. From Contact Where ID IN : selectedContactIds];
  41. system.debug('objConList :'+objConList);
  42. return objConList;
  43. }
  44.  
  45.  
  46. private void setSelectedContacts()
  47. {
  48. for(contactwrapper item: objAWList)
  49. {
  50. if(item.IsSelected)
  51. {
  52. if(!this.selectedContactIds.contains(item.ContactId))
  53. {
  54. this.selectedContactIds.add(item.ContactId);
  55. }
  56. }
  57. else
  58. {
  59. if(this.selectedContactIds.contains(item.ContactId))
  60. {
  61. this.selectedContactIds.remove(item.ContactId);
  62. }
  63. }
  64. }
  65. }
  66.  
  67. public integer PageIndex {
  68. get { return (PageNumber - 1); }
  69. }
  70.  
  71. public integer PageCount {
  72. get { return getPageCount(); }
  73. }
  74.  
  75. public integer Offset {
  76. get { return (PageSize * PageIndex); }
  77. }
  78.  
  79.  
  80. public void runSearch() {
  81. objAWList = new List<contactwrapper>();
  82. try {
  83. List<Contact> objConList = new List<Contact>();
  84. String contactName = Apexpages.currentPage().getParameters().get('ContactName');
  85.  
  86. if (!contactName.equals('')){
  87. soql = 'select firstname, lastname, Name,account.name,Job_Title__c,Account_Cust__c from contact where account.name != null';
  88. soql += ' and name LIKE '%' + contactName + '%'';
  89. soql += ' order by firstName ASC limit '+PageSize +' offset '+Offset;
  90. system.debug('soqlfinal::'+soql);
  91. objConList = Database.query(soql);
  92. RecordCount = objConList.size();
  93.  
  94. }else if(contactName.equals('')){
  95. RecordCount = objConList.size();
  96. objConList.clear();
  97. }
  98.  
  99. system.debug('objConList---'+objConList);
  100. if(!objConList.isEmpty()){
  101. for(Contact Con : objConList){
  102. ContactWrapper objAW = new ContactWrapper();
  103. objAW.ContactId = Con.Id;
  104. objAW.ContactName = Con.Name;
  105. objAW.AccountCust= Con.Account_Cust__c ;
  106. objAW.JobTitle= Con.Job_Title__c;
  107.  
  108. if(this.selectedContactIds.contains(con.Id)){
  109. objAW.IsSelected = true;
  110. }
  111. else{
  112. objAW.IsSelected = false;
  113. }
  114. objAWList.Add(objAW);
  115. }
  116. }
  117.  
  118. }
  119. catch (QueryException e) {
  120. ApexPages.addMessages(e);
  121.  
  122. }
  123. }
  124.  
  125. public integer LNumber {
  126. get { return RecordCount == 0 ? 0 : (Offset + 1); }
  127. }
  128.  
  129. public integer UNumber {
  130. get {
  131. integer iUNum = ((LNumber + PageSize) - 1);
  132. return (iUnum > RecordCount) ? RecordCount : iUNum;
  133. }
  134. }
  135.  
  136. public boolean AllowMoveNext {
  137. get{ return ((PageIndex + 1) < PageCount); } } public boolean AllowMovePrev { get{ return (PageIndex > 0); }
  138. }
  139.  
  140. public void Prev() {
  141. setSelectedContacts();
  142. PageNumber--;
  143.  
  144. if (PageNumber <= 0) { PageNumber = 1; } } public void Next() { setSelectedContacts(); PageNumber++; if (PageNumber > PageCount) {
  145. PageNumber = PageCount;
  146. }
  147. }
  148.  
  149. public void Last() {
  150. setSelectedContacts();
  151. PageNumber = PageCount;
  152. }
  153.  
  154. public void First() {
  155. setSelectedContacts();
  156. PageNumber = 1;
  157. }
  158.  
  159. private integer getPageCount() {
  160. integer iPageCount = 1;
  161.  
  162. if (RecordCount != 0 && PageSize != 0) {
  163. iPageCount = (RecordCount/PageSize) + ((Math.mod(RecordCount, PageSize)) > 0 ? 1 : 0);
  164. }
  165. return iPageCount;
  166. }
  167.  
  168. public class Contactwrapper
  169. {
  170. public Id ContactId {get;set;}
  171. public String ContactName {get;set;}
  172. public String AccountCust {get;set;}
  173. public String JobTitle {get;set;}
  174. public Boolean IsSelected{get;set;}
  175. public Contactwrapper()
  176. {
  177.  
  178. }
  179. }
  180. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement