Advertisement
Guest User

Untitled

a guest
Feb 9th, 2016
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.52 KB | None | 0 0
  1. public with sharing class IntegrationContactsController{
  2.  
  3.     private ApexPages.StandardController sController;  
  4.     public List<Contact> integrationContacts {get; set;}
  5.     public Id integrationUser {get; set;}
  6.  
  7.     //this is used for choosing groups of five records to show on related list
  8.     public Integer groupNumber = 1;
  9.     public String previousClass { get; set; }
  10.     public String nextClass { get; set; }
  11.     public Integer minIndex { get; set; }
  12.     public Integer maxIndex { get; set; }
  13.  
  14.     public final Integer groupSize = 5;
  15.  
  16.     public IntegrationContactsController(ApexPages.StandardController controller){
  17.         sController = controller;
  18.     }
  19.  
  20.  
  21.     public List<Contact> getContacts() {
  22.         integrationUser = [SELECT ID FROM User where Name = 'integration'].Id;
  23.         integrationContacts = [SELECT Id, Name, Source__c,Email,Phone, MobilePhone, CreatedDate FROM Contact where OwnerId =: integrationUser ORDER BY CreatedDate DESC];
  24.  
  25.         return sublist(this.integrationContacts, groupSize  (groupNumber - 1), groupSize  groupNumber);
  26.     }
  27.     public void nextGroup() {
  28.         if (groupNumber*groupSize < integrationContacts.size()) {
  29.             groupNumber++;
  30.         }
  31.     }
  32.     public void previousGroup() {
  33.         if (groupNumber > 1) {
  34.             groupNumber--;
  35.         }
  36.     }
  37.     public void lastGroup() {
  38.         groupNumber = Integer.valueOf(Decimal.valueOf(Double.valueOf(integrationContacts.size())/groupSize).round(System.RoundingMode.CEILING));
  39.     }
  40.     public void firstGroup() {
  41.         groupNumber = 1;
  42.     }
  43.  
  44.     private void verifyClassesAndIndexes() {
  45.         if (groupNumber*groupSize >= integrationContacts.size()) {
  46.             nextClass = 'inactive';
  47.         } else {
  48.             nextClass = '';
  49.         }
  50.         if (groupNumber <= 1) {
  51.  
  52.             previousClass = 'inactive';
  53.         } else {
  54.             previousClass = '';
  55.         }
  56.         minIndex = integrationContacts.size() > 0? (groupNumber - 1)*groupSize + 1 : 0;
  57.         maxIndex = (groupNumber*groupSize) > integrationContacts.size()? integrationContacts.size() : (groupNumber*groupSize);
  58.     }
  59.  
  60.     private List<sObject> sublist(List<sObject> recordList, Integer fromIndex, Integer toIndex) {
  61.         List<sObject> resultList = new List<sObject>();
  62.         for (Integer i = fromIndex; i < toIndex; i++) {
  63.             if (i < recordList.size()){
  64.                 resultList.add(recordList[i]);
  65.             }
  66.         }
  67.         verifyClassesAndIndexes();
  68.         return resultList;
  69.     }
  70.  
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement