• Febreeze
  • NEWBIE
  • 0 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 1
    Replies
here is my vf page
  1. <apex:page controller="Pagination" sidebar="false" showHeader="false">
    
     
        <script type="text/javascript"> 
            /*
            *    function to handle checkbox selection
            */
            function doCheckboxChange(cb,itemId){
     
                if(cb.checked==true){
                    aSelectItem(itemId);
                }
                else{
                    aDeselectItem(itemId);
                }
                }
                    </script>
        <apex:form >
        <!-- handle selected item -->
            <apex:actionFunction name="aSelectItem" action="{!doSelectItem}" rerender="ThePage">
                <apex:param name="contextItem" value="" assignTo="{!contextItem}"/>
            </apex:actionFunction>
     
            <!-- handle deselected item -->
            <apex:actionFunction name="aDeselectItem" action="{!doDeselectItem}" rerender="ThePage">
                <apex:param name="contextItem" value="" assignTo="{!contextItem}"/>
            </apex:actionFunction>
               
            <apex:pageBlock id="ThePage">
                <apex:pageBlockTable value="{!wrapperClass}" var="p">
                <apex:column >
                        <apex:facet name="header">Action</apex:facet>
                        <apex:inputCheckbox value="{!p.selectedObject}" onchange="doCheckboxChange(this,'{!p.productObject.Id}')"/>
                    </apex:column>
                   
                    <apex:column ><apex:facet name="header">
                    
                    <apex:commandLink value="Name {!if(compareField == 'Name' ,  if(sortOrder = 'asc' , '▼','▲' ), NULL )}" action="{!sortedList}" reRender="ThePage">
                    <apex:param name="compareField" value="Name" assignTo="{!compareField}"/>
                    <apex:param name="orderType" value="{!if(sortOrder='asc', 'desc', 'asc')}" assignTo="{!sortOrder}"/>
                    
                  </apex:commandLink></apex:facet><apex:outputField value="{!p.productObject.name}"/></apex:column>
                  <apex:column headerValue="List Price">
                  <apex:inputField value="{!p.productObject.ListPrice__c}"/></apex:column>
                 
                    <apex:column headervalue="Standard Price" value="{!p.productObject.StandardPrice__c}"/>
                    <apex:column headervalue="Quantity"><apex:inputField value="{!p.productObject.Quantity__c}"/></apex:column>
                </apex:pageBlockTable>
               <apex:pageBlockButtons >
                <apex:commandButton rendered="{!setCon.hasPrevious}" value="first" action="{!setCon.first}"/>
                <apex:commandButton rendered="{!setCon.hasPrevious}" value="Previous" action="{!setCon.previous}"/>
                <apex:commandButton rendered="{!setCon.hasNext}" value="next" action="{!setCon.next}"/>
               
                <apex:commandButton rendered="{!setCon.hasNext}" value="last" action="{!setCon.last}"/>
            </apex:pageBlockButtons>
            </apex:pageBlock>
        </apex:form>
    
    </apex:page>
    
and here is my controller for the same
global with sharing class Pagination {

     public list<wrapperClass> wrapperList {get ; set ;}
     public static String compareField {get;set;} // Holds the value of field on which the list needs to be sorted
     public static String sortOrder {get;set;} // Sorting order (ASC/DESC)
     public set<Id> idSet;//
     public String contextItem{get;set;}//checkbox related product records value

     
     public Pagination(){
	   this.idSet = new set<Id>();
     }
     
     
  // ApexPages.StandardSetController must be instantiated   
  // for standard list controllers       
     public ApexPages.StandardSetController setCon {
        get {
            if(setCon == null) {
                setCon = new ApexPages.StandardSetController(Database.getQueryLocator(
                      [select name,ListPrice__c , Quantity__c,StandardPrice__c from Product2 ORDER By Name ASC]));
                      
            }
            return setCon;
        }
        set;
    }

    /*
    *   handle item selected
    */
    public void doSelectItem(){
 
        this.idSet.add(this.contextItem);
 
    }
 
    /*
    *   handle item deselected
    */
    public void doDeselectItem(){
 
        this.idSet.remove(this.contextItem);
		
		}
		
    // Initialize setCon and return a list of records
   
    public list<wrapperClass> getwrapperClass() {
         setCon.setpagesize(5);
         wrapperList = new List<wrapperClass>();
         
         
         for (Product2 product2Object : (List<Product2>)setCon.getRecords()) {
         
             wrapperClass wrapperObject = new wrapperClass(product2Object);
             if(idSet.contains(product2Object.id)){
					wrapperObject.selectedObject = true;
         
           }
         
           else{
				wrapperObject.selectedObject = false;
           }
         
            wrapperList.add(wrapperObject);
      }
        return wrapperList;
    }
	/*to sort the wrapper list in ascending or descending*/
	
	public void sortedList(){
      wrapperList.sort();
      }
	  
	  
    /*custom sort*/
    global class wrapperClass implements Comparable{
      
      public Boolean selectedObject {get ; set;}
      public Product2 productObject {get ; set;}
      
      public wrapperClass(Product2 p){
      
      productObject = p;
      selectedObject = false;
      
      }
      
      global Integer compareTo(Object producttypeObject){
      
      wrapperClass compareObject = (wrapperClass)producttypeObject;
      
      if ((String)productObject.get(compareField) > (String)compareObject.productObject.get(compareField)) {
      
      if(sortOrder.equals('asc'))  {
      return 1; 
      }
      
      else { 
        return 0; 
        }
      }
      
      else {
      if(sortOrder.equals('asc'))  {return 0; } else{ return 1; }
      }
           
      }
      }
      
      
    }

when i enter a value in my list price input field , on paginating to next page or previous and coming back to the same page the entered value must be retained..  the value should be present in my wrapper class list and not in my actual records.


 and also i m stuck at the custom sorting part on cicking any fields header value like name or list price my list order must be sorted in ascending first and again clicking sorts it to descending
 can anyone help me with this...
Thanks in advance
Hi, I have a requirement wherein , i have a custom setting with records that have fields as below:
1.Source Object
2.Source Field
3.Destination Object
4.Destination Field
for example if i have a record with such field values
1.Source Object: Account
2.Source Field:Name
3.Destination Object:Contact
4.Destination Field:LastName

then i have to write a batch apex that will create records into destination object with the given destination field with value  , from source objects  source values...it will be reflected as below:

Account- Name:Rahul then after running the batch apex
Contact-LastName : Rahul. 

please help me resolve it 
Thanks in advance.
Hi, I have a requirement wherein , i have a custom setting with records that have fields as below:
1.Source Object
2.Source Field
3.Destination Object
4.Destination Field
for example if i have a record with such field values
1.Source Object: Account
2.Source Field:Name
3.Destination Object:Contact
4.Destination Field:LastName

then i have to write a batch apex that will create records into destination object with the given destination field with value  , from source objects  source values...it will be reflected as below:

Account- Name:Rahul then after running the batch apex
Contact-LastName : Rahul. 

please help me resolve it 
Thanks in advance.