• Sudhir_Meru
  • NEWBIE
  • 385 Points
  • Member since 2013

  • Chatter
    Feed
  • 5
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 99
    Questions
  • 172
    Replies

Hi, 

  There are few javascript supporting files uploaded in status resources please suggest me how to call. 

How to call below link in visualforce
 <script src="../assets/js/jquery-ui.custom.min.js"></script>

I am calling css files as mentioned below. 
<apex:stylesheet value="{!URLFOR($Resource.assets, 'assets/css/bootstrap.min.css')}" />

Thanks

Sudhir

Hi, 

  I created a css file inside folder name cssexample 

style.css file name
================
h1
{
  text-align:center;
  color:green;
}


made 
cssexample.zip and uploaded in static resources


I am calling in visual force page it is not referencing Please suggest me what is the issue

<apex:page standardstylesheets="false" showheader="false">

<apex:stylesheet value="{!URLFOR($Resource.cssex, 'style.css')}" />

<h1> This text is displayed using CSS </h1>
</apex:page>

Hi,

  We purchased a template onlin which has .css images .js etc files we are developing a service cloud application and we will be using this template in our app. Please suggest us how to call this template in visualforce page.

Thanks

Sudhir

Hi, 

  I have put a trigger on appoinment object which will fire to update lead status Please see below code 
trigger Update_Lead_Status on Appointment_Detail__c (After Insert, Before Update) 
{
 
 Appointment_Detail__c ApptDt = [ SELECT  Completed__c,Lead_Id__c  FROM Appointment_Detail__c where id in :Trigger.newMap.keySet()];  
     
    If ( ApptDt.Lead_Id__c <> null && ApptDt.Completed__c == 'Yes' ) 
    {
      Lead ld = [select staTus from Lead where id = :ApptDt.Lead_Id__c]; 
        if ( ld.status <> 'SQL') 
        {
         ld.status = 'SQL';
         update ld;      
         } 
      
    }  
  }
There is another trigger on Lead which will again update appoinment object please see code

//Created by Unnat Shrestha on March 30, 2014
//The functionality of this trigger is to reparent the child object, "Appointment Details" of Lead to Opportunity during the Lead Conversion

trigger reparent_Lead_children on Lead (after update) {
    //Creating a map between Lead and Opportunity
    Map<Id, Id> lead2Opp= new Map<Id, Id>();
    //Map<Id, Id> lead2Acc = new Map<Id, Id>();
    Map<Id, Id> lead2Cont = new Map<Id, Id>();
    
    for (Lead l : Trigger.new)
    {
        System.debug('Entered the for loop');
        //if (l.isConverted && l.convertedOpportunityId != null)
        if (l.isConverted) {
            if (l.convertedOpportunityId != null) {       
                //adding the values into the Map
                lead2Opp.put(l.Id, l.convertedOpportunityId);
            }
            //lead2Acc.put(l.Id, l.convertedAccountId);
            lead2Cont.put(l.Id, l.convertedContactId);
        }
    }
    System.debug('The Map values are:' + lead2Opp);
    List<Appointment_Detail__c> apptDetails = [select account__c, contact__c, lead_Id__c, opportunity_Id__c from Appointment_Detail__c where lead_Id__c in :lead2Opp.keySet()];
    for (Appointment_Detail__c appointment : apptDetails)
    {
        //assigning the Opportunity Id based on this lead id
        appointment.opportunity_Id__c = lead2Opp.get(appointment.lead_Id__c);
        //appointment.account__c = lead2Acc.get(appointment.lead_Id__c);
        appointment.contact__c = lead2Cont.get(appointment.lead_Id__c);
        System.debug('For Appointments, Changed the grabbed the opportunity id');
    }
    
    System.debug('before update');
    //Update the list if there is any
    if (apptDetails.size() > 0) {
        update apptDetails;
    }
    
    //re-parent the E-Rate to Opportunity as well
    List<E_Rate__c> eRates= [select lead__c, contact__c, opportunity__c from E_Rate__c where lead__c in :lead2Opp.keySet()];
    for (E_Rate__c eRate: eRates)
    {
        //assigning the Opportunity Id based on this lead id
        eRate.opportunity__c = lead2Opp.get(eRate.lead__c);
        eRate.contact__c = lead2Cont.get(eRate.lead__c);
        
        System.debug('For E-Rate, Changed the grabbed the opportunity id');
    }
    
    System.debug('before update- 2nd time');
    //Update the list if there is any
    if (eRates.size() > 0) {
        update eRates;
    }

}

Now when I convert lead to opportunity I am gettin below error

Error: System.DmlException: Update failed. First exception on row 0 with id 00Q6000000myNGaEAM; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, reparent_Lead_children: execution of AfterUpdate caused by: System.DmlException: Update failed. First exception on row 0 with id a1gm000000001G9AAI; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, Update_Lead_Status: execution of BeforeUpdate caused by: System.DmlException: Update failed. First exception on row 0 with id 00Q6000000myNGaEAM; first error: CANNOT_UPDATE_CONVERTED_LEAD, cannot reference converted lead: [] Trigger.Update_Lead_Status: line 12, column 1: [] Trigger.reparent_Lead_children: line 37, column 1: [] (System Code)

Please suggest me how to fix this issue

Thanks
Sudhir
Hi, 

  I wrote a pagination using wrapper class. Problem am facing is search is not getting cleared in visual force page. Please suggest me how to clear \

public with sharing class CCW_ContactPaginationController {
  public boolean createTemp = true; 
  public boolean OnlyForTestRun = true;
  //URL Passing Parameters. 
  String cancelURL;
  public String PageContractId = ApexPages.currentPage().getParameters().get('ContractId');     
  public String PageAccountId  = ApexPages.currentPage().getParameters().get('AccountId');   
  
 public string baseURL{get;set;}
 public String existingId{get;set;}

  public Asset   GetAccount{get;set;}
  public Asset   GetContract{get;set;} 
  public Asset   GetExpireDate{get;set;}
  public Asset   GetReseller{get;set;}
  public Asset   GetDistributor{get;set;}
  public String  IncumbentReseller{get;set;}
  public String  Education{get;set;}
  public Asset   GetOpportunity{get;set;}
  public Asset   GetNewOpportunity{get;set;}
  public String  ExpireTerms{get;set;}
  public boolean bundsprt{get;set;}
  public boolean Monthly_Quote {get;set;}
  public String pricebook {get; set;}
  
  //Our collection to class/wrapper objects wrapAsset
  public List<CCWRowItem> wrapAssetList {get; set;}
  public List<Asset> selectedAssets{get;set;} 
  public List<Temp_Assets__c>  TempAssetList;
   /*
    *   item in context from the page
    */
    public String contextItem{get;set;}
    public String contextItem2{get;set;}
 
 
    /*
    *   set controller
    */
    public ApexPages.StandardSetController setCon;
    
    
    /*
    *   the contact ids selected by the user
    */
    private Set<Id> selectedContactIds;
    private Set<Id> selectedContactIds2= new set<Id>();
    
    
    /*
    *   constructor
    */
    public CCW_ContactPaginationController()
    {    
      GetAccount = new Asset();    //Get Account Id from Page 
      GetContract = new Asset();   //Get Contract Name from Page   
      GetExpireDate = new Asset();   // Date Picker   
      GetReseller = new Asset(); 
      GetDistributor = new Asset();  
      GetOpportunity = new Asset();   // Get Opportunity Id 
      GetNewOpportunity = new Asset();  // Get New Opportunity Name    
      
      fetch_data(); 
            
      if (PageAccountId !=null ) { cancelURL = pageAccountId;
      }
      else if (PageContractId != null ) { cancelURL = PageContractId; }
      else { cancelURL = 'home/home.jsp'; }
      System.debug('### Contract Id is: '+ PageContractId);
      System.debug('### Account Id is: '+ PageAccountId);
      
     }
   
   
   /***************************************Sorting functionality Added******************************************************/
   public String sortDir {
        // To set a Direction either in ascending order or descending order.
        get  { if (sortDir == null) {  sortDir = 'desc'; } return sortDir;}
        set;
    }

    // the current field to sort by. defaults to last name
    public String sortField {
        // To set a Field for sorting.
        get  { if (sortField == null) {sortField = 'Service_End_Date_Max__c'; } return sortField;  }
        set;
    }
    
    //Declaring Variables for Dynamic SOQL
    public String soql {get; set;}
    Set<id> accId = new Set<Id>();
    Set<Id> contractId = new Set<Id>();
    
   /***************************************Sorting functionality ends here**************************************************/    
   public void fetch_data ()
   {
        // simply toggle the direction
        sortDir = sortDir.equals('asc') ? 'desc' : 'asc';
        //init variable
        this.selectedContactIds= new Set<Id>();
        //gather data set        

      //instantiating the query
      soql = 'SELECT Id, AccountId,Product2Id,SerialNumber,last_contract_number__c, last_contract_Id__c, Service_Start_Date_Min__c, Service_End_Date_Max__c,InstallDate,Bundle_Support__c FROM Asset WHERE '; // AccountId IN ';         
      
      Try 
       {  
      
       if ( GetAccount.AccountId == NULL && GetContract.Name == NULL )   
        {   
       
         if ( PageAccountId != NULL && PageContractId == NULL ) {  accId.add(pageAccountId); soql += 'AccountId IN :accId Order by ' + sortField + ' ' + sortDir + ' Limit 1000'; }
           //below line commented for Sorting       
          //this.setCon = new ApexPages.StandardSetController( [SELECT Id, AccountId,Product2Id,SerialNumber,last_contract_number__c,Service_Start_Date_Min__c, Service_End_Date_Max__c,InstallDate,Bundle_Support__c FROM Asset WHERE AccountId = :PageAccountId Order by Service_End_Date_Max__c Desc Limit 1000] );
             //Adding the Account Id into the set so that it can be used in the dynamic SOQL
            // accId.add(pageAccountId);
            // soql = 'SELECT Id, AccountId,Product2Id,SerialNumber,last_contract_number__c, last_contract_Id__c, Service_Start_Date_Min__c, Service_End_Date_Max__c,InstallDate,Bundle_Support__c FROM Asset WHERE '; // AccountId IN ';
           //  soql += 'AccountId IN :accId Order by ' + sortField + ' ' + sortDir + ' Limit 1000';
            // this.setCon = new ApexPages.StandardSetController(Database.query(soql));
        // }
         else if ( PageAccountId == NULL && PageContractId != NULL ) { contractId.add(pageContractId);  soql += 'last_contract_ID__c IN :contractId Order by ' + sortField + ' ' + sortDir + ' Limit 1000';}
         
         /*Contract C;
         C = [SELECT Name, ContractNumber FROM Contract WHERE Id = :PageContractId Limit 1]; 
         this.setCon = new ApexPages.StandardSetController( [SELECT Id, AccountId,Product2Id,SerialNumber,last_contract_number__c,last_contract_ID__c,Service_Start_Date_Min__c, Service_End_Date_Max__c,InstallDate,Bundle_Support__c FROM Asset WHERE last_contract_number__c = :C.Name Order by Service_End_Date_Max__c Desc Limit 1000] );
         */    
            // contractId.add(pageContractId);
             //soql = 'SELECT Id, AccountId,Product2Id,SerialNumber,last_contract_number__c,last_contract_ID__c,Service_Start_Date_Min__c, Service_End_Date_Max__c,InstallDate,Bundle_Support__c FROM Asset WHERE '; //last_contract_ID__c IN';
             //soql += 'last_contract_ID__c IN :contractId Order by ' + sortField + ' ' + sortDir + ' Limit 1000';
             //this.setCon = new ApexPages.StandardSetController(Database.query(soql));
        // this.setCon = new ApexPages.StandardSetController( [SELECT Id, AccountId,Product2Id,SerialNumber,last_contract_number__c,last_contract_ID__c,Service_Start_Date_Min__c, Service_End_Date_Max__c,InstallDate,Bundle_Support__c FROM Asset WHERE last_contract_ID__c = :PageContractId Order by Service_End_Date_Max__c Desc Limit 1000] );
         
        // }
         else 
         { 
             accId.add('0013000000DULXG');
            // soql = 'SELECT Id, AccountId,Product2Id,SerialNumber,last_contract_number__c, last_contract_Id__c, Service_Start_Date_Min__c, Service_End_Date_Max__c,InstallDate,Bundle_Support__c FROM Asset WHERE '; //AccountId IN ';
             soql += 'AccountId IN :accId Order by ' + sortField + ' ' + sortDir + ' Limit 1000';
             //this.setCon = new ApexPages.StandardSetController(Database.query(soql));
         //this.setCon = new ApexPages.StandardSetController( [SELECT Id, AccountId,Product2Id,SerialNumber,last_contract_number__c,Service_Start_Date_Min__c, Service_End_Date_Max__c,InstallDate,Bundle_Support__c FROM Asset WHERE AccountId = '0013000000DULXG' Order by Service_End_Date_Max__c Desc Limit 1000] );                                            
         }
         //test
        // this.setCon = new ApexPages.StandardSetController(Database.query(soql));
        }
      else if ( GetAccount.AccountId != NULL && GetContract.Name == NULL ) {  accId.add(GetAccount.AccountId); soql += 'AccountId IN :accId Order by ' + sortField + ' ' + sortDir + ' Limit 1000'; }
            //this.setCon = new ApexPages.StandardSetController( [SELECT Id, AccountId,Product2Id,SerialNumber,last_contract_number__c,Service_Start_Date_Min__c, Service_End_Date_Max__c,InstallDate,Bundle_Support__c FROM Asset WHERE AccountId = :GetAccount.AccountId Order by Service_End_Date_Max__c Desc Limit 1000] ); 
        
           /* accId.add(GetAccount.AccountId);
            System.debug('==== This if statement with set as: ' + accId);
            System.debug('==== This if statement with accId as: ' + GetAccount.AccountId);
          //  soql = 'SELECT Id, AccountId,Product2Id,SerialNumber,last_contract_number__c, last_contract_Id__c, Service_Start_Date_Min__c, Service_End_Date_Max__c,InstallDate,Bundle_Support__c FROM Asset WHERE ';//AccountId IN ';
            soql += 'AccountId IN :accId Order by ' + sortField + ' ' + sortDir + ' Limit 1000';
           // this.setCon = new ApexPages.StandardSetController(Database.query(soql));
         } */
       else if ( GetAccount.AccountId == NULL && GetContract.Name != NULL ) { Contract c = [Select id from Contract where name =: GetContract.Name]; contractId.add(c.id); soql += 'last_contract_ID__c IN :contractId Order by ' + sortField + ' ' + sortDir + ' Limit 1000'; }
       /* System.debug('===GetContractName is: ' + GetContract.Name);
            Contract c = [Select id from Contract where name =: GetContract.Name];
            System.debug('===GetContractName is: ' + c);
            contractId.add(c.id);
           // soql = 'SELECT Id, AccountId,Product2Id,SerialNumber,last_contract_number__c,last_contract_ID__c,Service_Start_Date_Min__c, Service_End_Date_Max__c,InstallDate,Bundle_Support__c FROM Asset WHERE ';//last_contract_ID__c IN';
            soql += 'last_contract_ID__c IN :contractId Order by ' + sortField + ' ' + sortDir + ' Limit 1000';
           // this.setCon = new ApexPages.StandardSetController(Database.query(soql));
        
       //this.setCon = new ApexPages.StandardSetController( [SELECT Id, AccountId,Product2Id,SerialNumber,last_contract_number__c,Service_Start_Date_Min__c, Service_End_Date_Max__c,InstallDate,Bundle_Support__c FROM Asset WHERE last_contract_number__c  = :GetContract.Name Order by Service_End_Date_Max__c Desc Limit 1000] );
        } */
       else if ( GetAccount.AccountId != NULL && GetContract.Name != NULL ) {  accId.add(GetAccount.AccountId); Contract c = [Select id from Contract where name =: GetContract.Name]; contractId.add(c.id); soql += 'last_contract_ID__c IN :contractId AND AccountId IN' + ':accId Order by ' + sortField + ' ' + sortDir + ' Limit 1000';}
           /* accId.add(GetAccount.AccountId);
            Contract c = [Select id from Contract where name =: GetContract.Name];
            System.debug('===GetContractName is: ' + c);
            contractId.add(c.id);
           // soql = 'SELECT Id, AccountId,Product2Id,SerialNumber,last_contract_number__c,last_contract_ID__c,Service_Start_Date_Min__c, Service_End_Date_Max__c,InstallDate,Bundle_Support__c FROM Asset WHERE '; //last_contract_ID__c IN';
            soql += 'last_contract_ID__c IN :contractId AND AccountId IN' + ':accId Order by ' + sortField + ' ' + sortDir + ' Limit 1000';
            //this.setCon = new ApexPages.StandardSetController(Database.query(soql));
            
        //this.setCon = new ApexPages.StandardSetController( [SELECT Id, AccountId,Product2Id,SerialNumber,last_contract_number__c,Service_Start_Date_Min__c, Service_End_Date_Max__c,InstallDate,Bundle_Support__c FROM Asset WHERE AccountId = :GetAccount.AccountId and last_contract_number__c = :GetContract.Name  Order by Service_End_Date_Max__c Desc  Limit 1000] );
        } */
       else { this.setCon = new ApexPages.StandardSetController( [SELECT Id, AccountId,Product2Id,SerialNumber,last_contract_number__c,Service_Start_Date_Min__c, Service_End_Date_Max__c,InstallDate,Bundle_Support__c FROM Asset WHERE AccountId = '0013000000DULXG' Order by Service_End_Date_Max__c Desc Limit 1000] ); } 
        this.setCon = new ApexPages.StandardSetController(Database.query(soql));   
        System.debug('##== Setcon is returning: '+ this.setcon.getrecord());
      }
      
      catch(Exception e) { this.setCon = new ApexPages.StandardSetController( [SELECT Id, AccountId,Product2Id,SerialNumber,last_contract_number__c,Service_Start_Date_Min__c, Service_End_Date_Max__c,InstallDate,Bundle_Support__c FROM Asset WHERE AccountId = '0013000000DULXG' Order by Service_End_Date_Max__c Desc Limit 1000] );  }            
       
        if(this.setCon != null){                                        
        this.setCon.setpageNumber(1);
        this.setCon.setPageSize(25);
        }
   } 
   
       
    /*
    *   handle item selected
    */
    public void doSelectItem(){        
        this.selectedContactIds.add(this.contextItem);     
        System.debug('##== SelectedContactIDs is: '+ selectedContactIds);   
    }
    
    public void doSelectItem2(){        
        this.selectedContactIds2.add(this.contextItem2);   
        System.debug('##== SelectedContactIDs2 is: '+ selectedContactIds2);       
    }
    
    
    /*
    *   handle item deselected
    */
    public void doDeselectItem(){        
        this.selectedContactIds.remove(this.contextItem);        
    }
    
    public void doDeselectItem2(){        
        this.selectedContactIds2.remove(this.contextItem2);        
    }
    
    
    /*
    *   return count of selected items
    */
    public Integer getSelectedCount(){
        System.debug('##== Size of the selectedCount is: '+ this.selectedContactIds.size());
        return this.selectedContactIds.size();
        
    }
    
    
    /*
    *   advance to next page
    */
    public void doNext(){        
        if(this.setCon.getHasNext()){ this.setCon.next();}
    }     
    
    
    /*
    *   advance to previous page
    */
    public void doPrevious(){        
        if(this.setCon.getHasPrevious()) { this.setCon.previous(); }
    }
    
    public List<CCWRowItem> rows {get; set;}
    
    /*
    *   return current page of groups
    */
    public List<CCWRowItem> getContacts(){        
       try  
        {
        rows = new List<CCWRowItem>();      
        System.debug('##== rows is: '+ rows);
        for(sObject r : this.setCon.getRecords()){
            Asset c = (Asset)r;
            System.debug('##== 1 - sellected contactids ' + this.selectedContactIds);
            System.debug('##== 1 - Asset c is: ' + c);
            CCWRowItem row = new CCWRowItem(c);
            if(this.selectedContactIds.contains(c.Id)){ row.IsSelected=true; if (this.selectedContactIds2.contains(c.Id)){
                    row.BundelSelected=true; bundsprt=true;
                }
                else { row.BundelSelected=false; bundsprt=false;
                }
            }
            else { row.IsSelected=false;
            }
            rows.add(row);            
        }             
        return rows;
        }
        catch(Exception e) { return null; }     
    }
  
  //Retrieve the Record Type id for Renewals Opportunity for the SOQL query
  RecordType renewal_RT = [Select id, Name, sObjectType from RecordType where sObjectType= 'Opportunity' and Name = 'Renewal Opportunity' ];
  
 // Store Selected Records to Object/Table
    public PageReference processSelected() {
        Integer currentPageNumber = setCon.getPageNumber();
        selectedAssets = new List<Asset>();
        //list<Temp_Assets__c> TempAssetList = new list<Temp_Assets__c>();  
        TempAssetList = new list<Temp_Assets__c>();      
        
        setCon.setpageNumber(1);
        PageReference resend;
        
        
        while(true){
            List<Asset>  TempAssetLists = (List<Asset>)setCon.getRecords();
            System.debug('### TempAssetlist are: '+ tempAssetLists);
            //TempAssetLists = (List<Asset>)setCon.getRecords();
            for(Asset assetIns : TempAssetLists  ) {
              System.debug('###= Inside the for loop');
              if(this.selectedContactIds.contains(assetIns.Id)){ selectedAssets.add(assetIns);
              }
              
            }
            System.debug('###= Selected Assets are: '+ selectedAssets);
            if(setCon.getHasNext()){setCon.next();
            }
            else{
                break;
            } 
   
        }  
        /**********Added by Unnat*********************************/
        //below code should only execute if Expiry term has a value
        Date maxDate; //=Date.valueOf('2000-1-1');
        Date minDate;
        System.debug('### selected Assets is: ' + selectedAssets);
        //Calculate the maximum Date off of the selected dates
      
        //finds the latest expiry date out of the selected assets
        for (Asset assets: selectedAssets) {
            if((assets.Service_End_Date_Max__c > maxDate) || (maxDate == null)) {
                maxDate=assets.Service_End_Date_Max__c;
            }
        }
        System.debug('== Latest Service end Date is:'+ maxDate);
        minDate = maxDate;
        for (Asset assets: selectedAssets) { if(minDate > assets.Service_End_Date_Max__c) { minDate=assets.Service_End_Date_Max__c;}
        }
        System.debug('== Least Service end Date is:'+ minDate);
        
        
      
        //Validations 
        if(!Test.isRunningtest()) {
        if ((selectedAssets.size() < 1 ) || (expireTerms == '0' && GetExpireDate.Expire_Date__c== null )|| (expireTerms != '0' && GetExpireDate.Expire_Date__c!= null ) || (GetDistributor.Primary_Distributor__c == null ) || (GetReseller.Primary_Reseller__c == null ) || (GetOpportunity.Opportunity__c==null && GetNewOpportunity.New_Opportunity__c== null ) || (GetOpportunity.Opportunity__c!=null && GetNewOpportunity.New_Opportunity__c!= null )|| (GetExpireDate.Expire_Date__c < maxDate ))
        {
            createTemp = false;
            //Validates that atleast one of the assets is selected from the install base
            if(selectedAssets.size() < 1 ){
                ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error,'Please select atleast one Asset to renew from the Install Base.'));
            }
            //Validates that atleast one of the Expiry Dates needs to have a value
            if(expireTerms == '0' && GetExpireDate.Expire_Date__c== null ){ ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error,'Please enter the Expiry Term or Expiry Date for the selected Assets.')); }
            //Valation that only of the Expirty Dates can have a value
            else if(expireTerms != '0' && GetExpireDate.Expire_Date__c!= null ){ ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error,'You can enter a value either in Expiry Date or Expiry Term, but not in both.')); }
            //Validation that the Distributor Name is required
            if(GetDistributor.Primary_Distributor__c == null ){
                ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error,'Please enter a value in Distributor'));
            }
            //Validation that Reseller Name is required
            if(GetReseller.Primary_Reseller__c == null ){
                ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error,'Please enter a value in Reseller'));
            } 
            //Validation that atleast one Opportunity needs to have a value
            if((GetOpportunity.Opportunity__c==null && GetNewOpportunity.New_Opportunity__c== null ) || (GetOpportunity.Opportunity__c!=null && GetNewOpportunity.New_Opportunity__c!= null )){
                ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error,'Please enter a value either in Opportunity or New Opportunity.'));
            }
          
            //Validation that will check if the Expiry Date has value less than the selected Asset Service End Date
            if(GetExpireDate.Expire_Date__c < maxDate ){ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error,'Expiry Date that you entered is lower than Service End Date of the Asset'));}
            if(pricebook == 'none') { ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error,'Please select the pricebook for this New Opportunity'));}         
           return null;
        }
        }
       // else {
        if  (createTemp = true) {
        //below code should only execute if Expiry term has a value
        //Date maxDate=Date.valueOf('2000-1-1');
        //Calculate the maximum Date off of the selected dates
        
        if (ExpireTerms !=null) {
        System.debug('== Expire Terms has a value');
            
            System.debug('== ExpireTerms is: '+ ExpireTerms);
            if (ExpireTerms=='1') {
                System.debug('== First if condition');
                maxDate=maxDate.addYears(1);
            }
            else if (ExpireTerms == '3') {
            System.debug('== Second if condition');
                maxDate=maxDate.addYears(3);
            }
            else if (ExpireTerms == '5') {
            System.debug('== third if condition');
                maxDate=maxDate.addYears(5);
            }
            else {
                maxDate= GetExpireDate.Expire_Date__c; 
            }
        }
        else {
            System.debug('== Else condition');
            maxDate= GetExpireDate.Expire_Date__c;   
        } 
        System.debug('== Max Date is: ' + maxDate);          
            System.debug('=- after the if condition');           
            Account ResellerAct; 
            Account DistributorAct;  
            Opportunity Oppt;           
          
            for(Asset Act : selectedAssets) {               
                Temp_Assets__c TempAsset = new Temp_Assets__c();
                TempAsset.Name = 'Sudhir';
                TempAsset.AccountId__c = Act.AccountId;
                TempAsset.Product__c = Act.Product2Id;
                //Added by Unnat
                TempAsset.Product_lookup__c= Act.Product2Id;
                System.debug('##== Product Id is: '+ Act.Product2Id);
                TempAsset.Asset_Id__c = Act.Id;
                TempAsset.Serial_Number__c = Act.SerialNumber;
                TempAsset.Last_Contract_Number__c = Act.last_contract_number__c; 
                TempAsset.Service_Start_Date__c = Act.Service_Start_Date_Min__c;
                TempAsset.Opp_Close_Date__c = minDate;
                TempAsset.Monthly_Quote__c = Monthly_Quote;
                System.debug('=- Monthly Quote is: ' + monthly_Quote);
                
                if (Act.Service_End_Date_Max__c != null) {
                    TempAsset.Service_End_Date__c = Act.Service_End_Date_Max__c;
                }
                else {
                    TempAsset.Service_End_Date__c = Act.InstallDate;
                }
                
                TempAsset.Install_Date__c = Act.InstallDate;  
                System.debug ('==== Reseller id is: '+ GetReseller.Primary_Reseller__c);
                TempAsset.Reseller__c = GetReseller.Primary_Reseller__c;
                TempAsset.Distributor__c = GetDistributor.Primary_Distributor__c;
                
                If ( GetOpportunity.Opportunity__c <> NULL )
                {
                Oppt = [SELECT Id FROM Opportunity WHERE ID = :GetOpportunity.Opportunity__c Limit 1];
                TempAsset.Existing_Opportunity__c = Oppt.Id;
                existingId = Oppt.Id; // Get Opportunity Id to Redirect Page
                }                
                TempAsset.Incumbent_Reseller__c = IncumbentReseller;
                TempAsset.Education__c = Education; 
                //TempAsset.Expiry_Date__c = GetExpireDate.Expire_Date__c;
                TempAsset.Expiry_Date__c= maxDate;
                TempAsset.PriceBook_Name__c = pricebook;
                
                TempAsset.New_Opportunity__c = GetNewOpportunity.New_Opportunity__c;
                TempAsset.Expiry_Term__c = ExpireTerms;
                
                /* Insert Bundel Checkbox Value */                
                if (this.selectedContactIds2.contains(Act.Id)){
                    bundsprt=true;
                }
                else {
                    bundsprt=false;
                }
                
                
                TempAsset.Bundle_Support__c = bundsprt; 
                System.debug('== Bundle Value is: ' + bundsprt);
                
                             //Add the selected Assets to the List
                TempAssetList.add(TempAsset);
            }
             
               System.debug('=--2 inserted the list');
               Insert TempAssetList;
               
               if ( GetNewOpportunity.New_Opportunity__c != null ) {
               System.debug('--inside the New opp');
                    Opportunity NewOpt; 
                   NewOpt = [SELECT Id, recordTypeId FROM Opportunity WHERE name = :GetNewOpportunity.New_Opportunity__c AND recordTypeId =: renewal_RT.id AND Support_Expiry_Date__c = :maxDate AND closeDate =: minDate and createdbyid = :UserInfo.getUserId() order by createddate desc Limit 1];
                   existingId = NewOpt.Id; // Get Opportunity Id to Redirect Page   
                   System.debug('-- Opp Id is: '+ newOpt.id);            
               }
               baseUrl = URL.getSalesforceBaseUrl().toExternalForm()+'/';
               System.debug('--Base URL is: '+ baseURL);
               resend = new PageReference(baseURL + existingId);
               resend.setRedirect(true);
                      
       }
      setCon.setpageNumber(currentPageNumber);
      
      return resend;
       
    }

    //Redirect to Account or Contract or Home page upon Cancel
    public PageReference Cancel() {
        return new PageReference('/' + cancelURL); 
    }
    
    /*
    *   return whether previous page exists
    */
    public Boolean getHasPrevious(){       
       try {return this.setCon.getHasPrevious(); } catch(Exception e) { return false;}
    }
   
    /*
    *   return whether next page exists
    */
    public Boolean getHasNext(){       
    try { return this.setCon.getHasNext(); } catch(Exception e) { return false;}
    }

    
    /*
    *   return page number
    */
    public Integer getPageNumber(){   
    try { return this.setCon.getPageNumber(); } catch(Exception e) { return 1; }
    }

    
    /*
    *    return total pages
    */
    Public Integer getTotalPages(){
    Decimal totalSize;
    Decimal pageSize;
    Decimal pages;
    try  
        { 
          totalSize = this.setCon.getResultSize();
          pageSize = this.setCon.getPageSize();      
          pages = totalSize/pageSize;
          return (Integer)pages.round(System.RoundingMode.CEILING);      
        }catch(Exception e) { return 1; }
    }

 
    
    /*
    *   helper class that represents a row
    */
    public with sharing class CCWRowItem{
        
        public Asset tContact{get;set;}
        public Boolean IsSelected{get;set;}
        public Boolean BundelSelected{get;set;}
         
        public CCWRowItem(Asset c){
            this.tContact=c;            
            this.IsSelected=false;
            this.BundelSelected=false;
        }
        
    } 
  
       
     
    
}


Hi

  Please suggest me how to add sorting in visual force page here is the my code below. 

Controller
-----------

public with sharing class CCW_ContactPaginationController {
 
  //URL Passing Parameters. 
  String PageContractId = ApexPages.currentPage().getParameters().get('ContractId');     
  String PageAccountId  = ApexPages.currentPage().getParameters().get('AccountId');   
  
 public string baseURL{get;set;}
 public String existingId{get;set;}

  public Asset   GetAccount{get;set;}
  public Asset   GetContract{get;set;} 
  public Asset   GetExpireDate{get;set;}
  public Asset   GetReseller{get;set;}
  public Asset   GetDistributor{get;set;}
  public String  IncumbentReseller{get;set;}
  public String  Education{get;set;}
  public Asset   GetOpportunity{get;set;}
  public Asset   GetNewOpportunity{get;set;}
  public String  ExpireTerms{get;set;}
  public boolean bundsprt{get;set;}
  public boolean Monthly_Quote {get;set;}
  
  //Our collection to class/wrapper objects wrapAsset
  public List<CCWRowItem> wrapAssetList {get; set;}
  public List<Asset> selectedAssets{get;set;} 
  List<Temp_Assets__c>  TempAssetList;
   /*
    *   item in context from the page
    */
    public String contextItem{get;set;}
    public String contextItem2{get;set;}
 
 
    /*
    *   set controller
    */
    private ApexPages.StandardSetController setCon;
    
    
    /*
    *   the contact ids selected by the user
    */
    private Set<Id> selectedContactIds;
    private Set<Id> selectedContactIds2= new set<Id>();
    
    
    /*
    *   constructor
    */
    public CCW_ContactPaginationController ()
    {
      GetAccount = new Asset();    //Get Account Id from Page 
      GetContract = new Asset();   //Get Contract Name from Page   
      GetExpireDate = new Asset();   // Date Picker   
      GetReseller = new Asset(); 
      GetDistributor = new Asset();  
      GetOpportunity = new Asset();   // Get Opportunity Id 
      GetNewOpportunity = new Asset();  // Get New Opportunity Name    
      fetch_data();        
     }
    
       
   public void fetch_data ()
   {
       
        //init variable
        this.selectedContactIds= new Set<Id>();
        //gather data set        
      Try 
       {  
       if ( GetAccount.AccountId == NULL && GetContract.Name == NULL )   
        {   
         if ( PageAccountId != NULL && PageContractId == NULL )
         {
          this.setCon = new ApexPages.StandardSetController( [SELECT Id, AccountId,Product2Id,SerialNumber,last_contract_number__c,Service_Start_Date_Min__c, Service_End_Date_Max__c,InstallDate,Bundle_Support__c FROM Asset WHERE AccountId = :PageAccountId Order by Service_End_Date_Max__c Desc Limit 1000] );
         }
         else if ( PageAccountId == NULL && PageContractId != NULL )
         {
         Contract C;
         C = [SELECT Name FROM Contract WHERE Id = :PageContractId Limit 1]; 
         this.setCon = new ApexPages.StandardSetController( [SELECT Id, AccountId,Product2Id,SerialNumber,last_contract_number__c,Service_Start_Date_Min__c, Service_End_Date_Max__c,InstallDate,Bundle_Support__c FROM Asset WHERE last_contract_number__c = :C.Name Order by Service_End_Date_Max__c Desc Limit 1000] );
         }
         else 
         { 
         this.setCon = new ApexPages.StandardSetController( [SELECT Id, AccountId,Product2Id,SerialNumber,last_contract_number__c,Service_Start_Date_Min__c, Service_End_Date_Max__c,InstallDate,Bundle_Support__c FROM Asset WHERE AccountId = '0013000000DULXG' Order by Service_End_Date_Max__c Desc Limit 1000] );                                            
         }
        }
      else if ( GetAccount.AccountId != NULL && GetContract.Name == NULL )   
        {
         this.setCon = new ApexPages.StandardSetController( [SELECT Id, AccountId,Product2Id,SerialNumber,last_contract_number__c,Service_Start_Date_Min__c, Service_End_Date_Max__c,InstallDate,Bundle_Support__c FROM Asset WHERE AccountId = :GetAccount.AccountId Order by Service_End_Date_Max__c Desc Limit 1000] ); 
        } 
       else if ( GetAccount.AccountId == NULL && GetContract.Name != NULL )
        { 
        this.setCon = new ApexPages.StandardSetController( [SELECT Id, AccountId,Product2Id,SerialNumber,last_contract_number__c,Service_Start_Date_Min__c, Service_End_Date_Max__c,InstallDate,Bundle_Support__c FROM Asset WHERE last_contract_number__c  = :GetContract.Name Order by Service_End_Date_Max__c Desc Limit 1000] );
        } 
       else if ( GetAccount.AccountId != NULL && GetContract.Name != NULL ) 
        {
        this.setCon = new ApexPages.StandardSetController( [SELECT Id, AccountId,Product2Id,SerialNumber,last_contract_number__c,Service_Start_Date_Min__c, Service_End_Date_Max__c,InstallDate,Bundle_Support__c FROM Asset WHERE AccountId = :GetAccount.AccountId and last_contract_number__c = :GetContract.Name  Order by Service_End_Date_Max__c Desc  Limit 1000] );
        } 
       else 
        { 
        this.setCon = new ApexPages.StandardSetController( [SELECT Id, AccountId,Product2Id,SerialNumber,last_contract_number__c,Service_Start_Date_Min__c, Service_End_Date_Max__c,InstallDate,Bundle_Support__c FROM Asset WHERE AccountId = '0013000000DULXG' Order by Service_End_Date_Max__c Desc Limit 1000] );                                            
        }    
      }
      
      catch(Exception e) {  
       this.setCon = new ApexPages.StandardSetController( [SELECT Id, AccountId,Product2Id,SerialNumber,last_contract_number__c,Service_Start_Date_Min__c, Service_End_Date_Max__c,InstallDate,Bundle_Support__c FROM Asset WHERE AccountId = '0013000000DULXG' Order by Service_End_Date_Max__c Desc Limit 1000] );                                            
        }            
       
        if(this.setCon != null){                                        
        this.setCon.setpageNumber(1);
        this.setCon.setPageSize(25);
        }
   } 
   
       
    /*
    *   handle item selected
    */
    public void doSelectItem(){        
        this.selectedContactIds.add(this.contextItem);        
    }
    
    public void doSelectItem2(){        
        this.selectedContactIds2.add(this.contextItem2);        
    }
    
    
    /*
    *   handle item deselected
    */
    public void doDeselectItem(){        
        this.selectedContactIds.remove(this.contextItem);        
    }
    
    public void doDeselectItem2(){        
        this.selectedContactIds2.remove(this.contextItem2);        
    }
    
    
    /*
    *   return count of selected items
    */
    public Integer getSelectedCount(){
        
        return this.selectedContactIds.size();
        
    }
    
    
    /*
    *   advance to next page
    */
    public void doNext(){        
        if(this.setCon.getHasNext())
            this.setCon.next();
          }     
    
    
    /*
    *   advance to previous page
    */
    public void doPrevious(){        
        if(this.setCon.getHasPrevious())
            this.setCon.previous();          
    }
    
    //public List<CCWRowItem> rows = new List<CCWRowItem>();
    
    public List<CCWRowItem> rows {get; set;}
    /*
    *   return current page of groups
    */
    public List<CCWRowItem> getContacts(){        
       try  
        {
        rows = new List<CCWRowItem>();      
        
        for(sObject r : this.setCon.getRecords()){
            Asset c = (Asset)r;
            
            CCWRowItem row = new CCWRowItem(c);
            if(this.selectedContactIds.contains(c.Id)){
                row.IsSelected=true;
                if (this.selectedContactIds2.contains(c.Id)){
                    row.BundelSelected=true;
                    bundsprt=true;
                }
                else {
                    row.BundelSelected=false;
                    bundsprt=false;
                }

            }
            else {
                row.IsSelected=false;
            }
            rows.add(row);            
        }
                
        return rows;
        }
        catch(Exception e) { 
           return null;
             }
        
    }
  
  //Retrieve the Record Type id for Renewals Opportunity for the SOQL query
  RecordType renewal_RT = [Select id, Name, sObjectType from RecordType where sObjectType= 'Opportunity' and Name = 'Renewal Opportunity' ];
  
 // Store Selected Records to Object/Table
 public PageReference processSelected() {
    Integer currentPageNumber = setCon.getPageNumber();
    selectedAssets = new List<Asset>();
    //list<Temp_Assets__c> TempAssetList = new list<Temp_Assets__c>();  
    TempAssetList = new list<Temp_Assets__c>();      
      
     setCon.setpageNumber(1);
     PageReference resend;
     

while(true){
    List<Asset>  TempAssetLists = (List<Asset>)setCon.getRecords();
    //TempAssetLists = (List<Asset>)setCon.getRecords();
    for(Asset assetIns : TempAssetLists  ) {
          if(this.selectedContactIds.contains(assetIns.Id)){
             selectedAssets.add(assetIns);
             
             
           }
     }
 if(setCon.getHasNext()){
  setCon.next();
  }
  else{
  break;
  } 
   
}  
        /**********Added by Unnat*********************************/
        //below code should only execute if Expiry term has a value
        Date maxDate=Date.valueOf('2000-1-1');
        Date minDate;
        
        //Calculate the maximum Date off of the selected dates
      
        //finds the latest expiry date out of the selected assets
        for (Asset assets: selectedAssets) {
            if(assets.Service_End_Date_Max__c > maxDate) {
                maxDate=assets.Service_End_Date_Max__c;
            }
        }
        System.debug('== Latest Service end Date is:'+ maxDate);
        minDate = maxDate;
        for (Asset assets: selectedAssets) {
            if(minDate > assets.Service_End_Date_Max__c) {
                minDate=assets.Service_End_Date_Max__c;
            }
        }
        System.debug('== Least Service end Date is:'+ minDate);
        
        
          
        //Validations 
        if ((selectedAssets.size() < 1 ) || (expireTerms == '0' && GetExpireDate.Expire_Date__c== null )|| (expireTerms != '0' && GetExpireDate.Expire_Date__c!= null ) || (GetDistributor.Primary_Distributor__c == null ) || (GetReseller.Primary_Reseller__c == null ) || (GetOpportunity.Opportunity__c==null && GetNewOpportunity.New_Opportunity__c== null ) || (GetOpportunity.Opportunity__c!=null && GetNewOpportunity.New_Opportunity__c!= null )|| (GetExpireDate.Expire_Date__c < maxDate ))
        {
            //Validates that atleast one of the assets is selected from the install base
            if(selectedAssets.size() < 1 ){
                ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error,'Please select atleast one Asset to renew from the Install Base.'));
            }
            //Validates that atleast one of the Expiry Dates needs to have a value
            if(expireTerms == '0' && GetExpireDate.Expire_Date__c== null ){
                ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error,'Please enter the Expiry Term or Expiry Date for the selected Assets.'));
            }
            //Valation that only of the Expirty Dates can have a value
            else if(expireTerms != '0' && GetExpireDate.Expire_Date__c!= null ){
                ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error,'You can enter a value either in Expiry Date or Expiry Term, but not in both.'));
            }
            //Validation that the Distributor Name is required
            if(GetDistributor.Primary_Distributor__c == null ){
                ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error,'Please enter a value in Distributor'));
            }
            //Validation that Reseller Name is required
            if(GetReseller.Primary_Reseller__c == null ){
                ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error,'Please enter a value in Reseller'));
            } 
            //Validation that atleast one Opportunity needs to have a value
            if(GetOpportunity.Opportunity__c==null && GetNewOpportunity.New_Opportunity__c== null ){
                ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error,'Please enter a value in either of the Opportunity'));
            }
            //Validation that only one of the Opportunities can have a value
            else if(GetOpportunity.Opportunity__c!=null && GetNewOpportunity.New_Opportunity__c!= null ){
                ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error,'You can enter a value either in Opportunity or New Opportunity, but not in both.'));
            }
            //Validation that will check if the Expiry Date has value less than the selected Asset Service End Date
            if(GetExpireDate.Expire_Date__c < maxDate ){
                ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error,'Expiry Date that you entered is lower than Service End Date of the Asset'));
            }
        }
        else {
        //below code should only execute if Expiry term has a value
        //Date maxDate=Date.valueOf('2000-1-1');
        //Calculate the maximum Date off of the selected dates
        
        if (ExpireTerms !=null) {
        System.debug('== Expire Terms has a value');
            //finds the latest expiry date out of the selected assets
           /***************************moved this upwards*********************************** 
           for (Asset assets: selectedAssets) {
                if(assets.Service_End_Date_Max__c > maxDate) {
                    maxDate=assets.Service_End_Date_Max__c;
                }
            }
            System.debug('== Latest Service end Date is:'+ maxDate);
            
            //Validation that will check if the Expiry Date has value less than the selected Asset Service End Date
            if(GetExpireDate.Expire_Date__c < maxDate ){
                ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error,'Expiry Date that you entered is lower than Service End Date of the Asset'));
            }
            *********************************************************************************/
            //There will be another condition to add the expiry term to the latest expiry date
            //String a='1 Year';
            System.debug('== ExpireTerms is: '+ ExpireTerms);
            if (ExpireTerms=='1') {
                System.debug('== First if condition');
                maxDate=maxDate.addYears(1);
            }
            else if (ExpireTerms == '3') {
            System.debug('== Second if condition');
                maxDate=maxDate.addYears(3);
            }
            else if (ExpireTerms == '5') {
            System.debug('== third if condition');
                maxDate=maxDate.addYears(5);
            }
            else {
                maxDate= GetExpireDate.Expire_Date__c; 
            }
           // resend = new PageReference('http://www.google.com');
           // resend.setRedirect(false);
        }
        else {
        System.debug('== Else condition');
            maxDate= GetExpireDate.Expire_Date__c;   
        } 
        System.debug('== Max Date is: ' + maxDate);
        Integer totalDays = minDate.daysBetween(maxDate); 
        System.debug('== Total days difference is: '+ totalDays);
        /****************Completed by Unnat*****************************/
        
        //checks if the Monthly Quote is going to be more than 36 months and Monthly Quote Checkbox is selected
        /*if (totalDays > 1080 && Monthly_Quote == true ) {
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error,'Since the Renewals in Months is more than 3 years, please uncheck the Monthly Quote checkbox'));
        }
        else {*/        
            System.debug('=- after the if condition');           
            Account ResellerAct; 
            Account DistributorAct;  
            Opportunity Oppt;           
                                
            for(Asset Act : selectedAssets)
            {               
                Temp_Assets__c TempAsset = new Temp_Assets__c();
                TempAsset.Name = 'Sudhir';
                TempAsset.AccountId__c = Act.AccountId;
                TempAsset.Product__c = Act.Product2Id;
                //Added by Unnat
                TempAsset.Product_lookup__c= Act.Product2Id;
                TempAsset.Asset_Id__c = Act.Id;
                TempAsset.Serial_Number__c = Act.SerialNumber;
                TempAsset.Last_Contract_Number__c = Act.last_contract_number__c; 
                TempAsset.Service_Start_Date__c = Act.Service_Start_Date_Min__c;
                
                //TempAsset.Service_End_Date__c = Act.Service_End_Date_Max__c;
                /***************Added by Unnat********************************************/
                TempAsset.Opp_Close_Date__c = minDate;
                TempAsset.Monthly_Quote__c = Monthly_Quote;
                System.debug('=- Monthly Quote is: ' + monthly_Quote);
                
                if (Act.Service_End_Date_Max__c != null) {
                    TempAsset.Service_End_Date__c = Act.Service_End_Date_Max__c;
                }
                else {
                    TempAsset.Service_End_Date__c = Act.InstallDate;
                }
                
                TempAsset.Install_Date__c = Act.InstallDate;  
                System.debug ('==== Reseller id is: '+ GetReseller.Primary_Reseller__c);
                TempAsset.Reseller__c = GetReseller.Primary_Reseller__c;
                TempAsset.Distributor__c = GetDistributor.Primary_Distributor__c;
                
                /****************Commented by Unnat****************************************************************************
                
                If (GetReseller.AccountId <> NULL) 
                {      
                ResellerAct = [ SELECT Id FROM Account WHERE ID = :GetReseller.Primary_Reseller__c Limit 1];
                TempAsset.Reseller__c = ResellerAct.Id;      
                 System.debug ('==== Reseller id 2 is: '+ ResellerAct.Id);        
                }
               
                If (GetDistributor.AccountId <> NULL )
                {
                DistributorAct = [ SELECT Id FROM Account WHERE ID = :GetDistributor.Primary_Distributor__c Limit 1];
                TempAsset.Distributor__c = DistributorAct.Id;
                }
                
                ****************Completed by Unnat *****************************************************************************/
                If ( GetOpportunity.Opportunity__c <> NULL )
                {
                Oppt = [SELECT Id FROM Opportunity WHERE ID = :GetOpportunity.Opportunity__c Limit 1];
                TempAsset.Existing_Opportunity__c = Oppt.Id;
                existingId = Oppt.Id; // Get Opportunity Id to Redirect Page
                }                
                TempAsset.Incumbent_Reseller__c = IncumbentReseller;
                TempAsset.Education__c = Education; 
                //TempAsset.Expiry_Date__c = GetExpireDate.Expire_Date__c;
                TempAsset.Expiry_Date__c= maxDate;
                
                TempAsset.New_Opportunity__c = GetNewOpportunity.New_Opportunity__c;
                TempAsset.Expiry_Term__c = ExpireTerms;
                
                /* Insert Bundel Checkbox Value */                
                if (this.selectedContactIds2.contains(Act.Id)){
                    bundsprt=true;
                }
                else {
                    bundsprt=false;
                }
                
                
                TempAsset.Bundle_Support__c = bundsprt; 
                System.debug('== Bundle Value is: ' + bundsprt);
                
                             //Add the selected Assets to the List
                TempAssetList.add(TempAsset);
            }
             
               System.debug('=--2 inserted the list');
               Insert TempAssetList;
               
               if ( GetNewOpportunity.New_Opportunity__c != null ) {
               System.debug('--inside the New opp');
                    Opportunity NewOpt; 
                   NewOpt = [SELECT Id, recordTypeId FROM Opportunity WHERE name = :GetNewOpportunity.New_Opportunity__c AND recordTypeId =: renewal_RT.id AND Support_Expiry_Date__c = :maxDate AND closeDate =: minDate and createdbyid = :UserInfo.getUserId() order by createddate desc Limit 1];
                   existingId = NewOpt.Id; // Get Opportunity Id to Redirect Page   
                   System.debug('-- Opp Id is: '+ newOpt.id);            
               }
               baseUrl = URL.getSalesforceBaseUrl().toExternalForm()+'/';
               System.debug('--Base URL is: '+ baseURL);
               resend = new PageReference(baseURL + existingId);
               resend.setRedirect(true);
                      
       // } //end of if Condition for check of days more than 3 years
       }
      setCon.setpageNumber(currentPageNumber);
      return resend;
        
    }

/* Do not need it anymore
 public PageReference pageRefMethod() {

   //call your action method
    processSelected();
    
  
 /*  if ( GetOpportunity.Opportunity__c != null ) {
                    Opportunity NewOpt; 
                   NewOpt = [SELECT Id FROM Opportunity WHERE id = :GetOpportunity.Opportunity__c Limit 1];
                   existingId = NewOpt.Id; // Get Opportunity Id to Redirect Page                   
                                           }
  
   else if ( GetNewOpportunity.New_Opportunity__c != null ) {
                    Opportunity NewOpt; 
                   NewOpt = [SELECT Id FROM Opportunity WHERE name = :GetNewOpportunity.New_Opportunity__c Limit 1];
                   existingId = NewOpt.Id; // Get Opportunity Id to Redirect Page               
                                           } 
                    
    baseUrl = URL.getSalesforceBaseUrl().toExternalForm()+'/';
    PageReference send = new PageReference(baseURL + existingId);
    send.setRedirect(true);
    return send;
   
    }
                      else {
                      return null;
                      } 
     
   

    }*/
      
    
    /*
    *   return whether previous page exists
    */
    public Boolean getHasPrevious(){       
       try  
        {
        return this.setCon.getHasPrevious();         
        }
        catch(Exception e) { 
           return false;
             }
    }
    
    
    /*
    *   return whether next page exists
    */
    public Boolean getHasNext(){       
    try  
        {
        return this.setCon.getHasNext();
        }
      catch(Exception e) { 
           return false;
             }
    }

    
    /*
    *   return page number
    */
    public Integer getPageNumber(){   
    try  
        {     
        return this.setCon.getPageNumber();        
    }
    catch(Exception e) { 
           return 1;
             }
    }

    
    /*
    *    return total pages
    */
    Public Integer getTotalPages(){
    Decimal totalSize;
    Decimal pageSize;
    Decimal pages;
    try  
        { 
          totalSize = this.setCon.getResultSize();
          pageSize = this.setCon.getPageSize();      
          pages = totalSize/pageSize;
          return (Integer)pages.round(System.RoundingMode.CEILING);      
        }
         catch(Exception e) { 
           return 1;
             }
    }

 
    
    /*
    *   helper class that represents a row
    */
    public with sharing class CCWRowItem{
        
        public Asset tContact{get;set;}
        public Boolean IsSelected{get;set;}
        public Boolean BundelSelected{get;set;}
         
        public CCWRowItem(Asset c){
            this.tContact=c;            
            this.IsSelected=false;
            this.BundelSelected=false;
        }
        
    }            
    
}


Thanks
Sudhir

Hi, 

  I have a requirement to sort visual force page. Please suggest me how to sort columns.  Please see my code and suggest me

<apex:page controller="CCW_ContactPaginationController"  showHeader="true" sidebar="true" > 
    
    <script type="text/javascript">
 
        /*
        *    function to handle checkbox selection
        */
        function doCheckboxChange(cb,itemId){
 
            if(cb.checked==true){
                aSelectItem(itemId);
            }
            else{
                aDeselectItem(itemId);
            }
 
        }
        function doCheckboxChange2(cb,itemId){
 
            if(cb.checked==true){
                aSelectItem2(itemId);
            }
            else{
                aDeselectItem2(itemId);
            }
 
        }        
        
 
    </script>
<!-- Using apex:pageMessages instead   
<script type="text/javascript">
function Validation()
{ 
  var val   = document.getElementById('{!$Component.RenewalForm.configblock.configsecblock.confignewopp.newopp}').value;  
  var oval  = document.getElementById('{!$Component.RenewalForm.configblock.configsecblock.configopport.existopp}').value;  
  var edate = document.getElementById('{!$Component.RenewalForm.configblock.configsecblock.configexpiredate.expredate}').value;  
  var eterm = document.getElementById('{!$Component.RenewalForm.configblock.configsecblock.configexpire.expterms}').value;
  var eresr = document.getElementById('{!$Component.RenewalForm.configblock.configsecblock.configreseller.resler}').value;
  var edstb = document.getElementById('{!$Component.RenewalForm.configblock.configsecblock.configdistrbutor.distbtr}').value;
  
  if ( edate == '' && eterm == '0' ) {
    alert('Enter either expire date or select expite term');
    return false;
     }
  else if ( edate != '' && eterm != '0' )
   {
    alert('Enter either expire date or select expite term');
    return false;
   }  
  else if ( eresr == '' && edstb == '' )
   {
    alert('Enter reseller and distributor details');
    return false;
   }
  else if ( eresr == '' && edstb != ''  )
   {
    alert('Enter reseller details');
    return false;
   }
  else if ( eresr != '' && edstb == '' )
   {
    alert('Enter distributor details');
    return false;
   }
  else if ( val == '' && oval == '') 
  {
    alert('Enter either existing opportunity or new opporutnity');
    return false;
    }
  else if ( val != '' && oval != '') 
  {
     alert('Enter either existing opportunity or new opporutnity');
     return false;
     }
  else     
     alert('Please check row in Install Based Report to saved records');
     return true;     
  }
</script>
Done commenting the javaScript code --> 
   
<apex:sectionHeader subtitle="Create Renewal Quote" title="Meru Networks"/>

<apex:form id="RenewalForm">
<apex:pageBlock id="filterblock">
<apex:pageBlockSection title="Filters" columns="3" id="filterblocksection">
<apex:inputField value="{!GetAccount.AccountId}" label="Account"/>
<apex:inputField value="{!GetContract.Name}" label="Contract" required="false"/>
<apex:commandButton action="{!fetch_data}" value="Fetch Data"></apex:commandbutton>

</apex:pageBlockSection>
</apex:pageBlock>        
                 
        
    <apex:pageBlock id="reportblock">
        <apex:pageMessages /> 
        <apex:pageBlockButtons id="reportbutton">
        <apex:commandButton value="Save Records" action="{!processSelected}"  /> 
        <apex:commandButton value="Cancel" onclick="window.top.close()"/>
        </apex:pageBlockButtons>
       
        <!-- handle selected item -->
        <apex:actionFunction name="aSelectItem" action="{!doSelectItem}" rerender="mpb">
            <apex:param name="contextItem" value="" assignTo="{!contextItem}"/>
        </apex:actionFunction>
        
        <apex:actionFunction name="aSelectItem2" action="{!doSelectItem2}" rerender="mpb">
            <apex:param name="contextItem2" value="" assignTo="{!contextItem2}" />
        </apex:actionFunction>
        
        <!-- handle deselected item -->
        <apex:actionFunction name="aDeselectItem" action="{!doDeselectItem}" rerender="mpb">
            <apex:param name="contextItem" value="" assignTo="{!contextItem}"/>
        </apex:actionFunction> 
        
        <apex:actionFunction name="aDeselectItem2" action="{!doDeselectItem2}" rerender="mpb">
            <apex:param name="contextItem2" value="" assignTo="{!contextItem2}"/>
        </apex:actionFunction>
             
       <apex:pageBlockSection title="Install Base" id="mpb" collapsible="true" columns="1" >

            <!-- table of data -->
            <apex:pageBlockTable title="Assets" value="{!Contacts}" var="c" id="reportblocktable" >
                <apex:column >
                    <apex:facet name="header">Action</apex:facet>
                    <apex:inputCheckbox value="{!c.IsSelected}" onclick="doCheckboxChange(this,'{!c.tContact.Id}')"/>
                </apex:column>
                <apex:column >
                    <apex:facet name="header">Bundle Support</apex:facet>
                    <apex:inputCheckbox value="{!c.BundelSelected}" onclick="doCheckboxChange2(this,'{!c.tContact.Id}')"/>
                 </apex:column>
                <apex:column value="{!c.tContact.AccountId}"/>
                <apex:column value="{!c.tContact.Product2Id}"/>
                <apex:column value="{!c.tContact.SerialNumber}"/>
                <apex:column value="{!c.tContact.last_contract_number__c}"/>
                <apex:column value="{!c.tContact.Service_Start_Date_Min__c}"/>
               <apex:column value="{!c.tContact.Service_End_Date_Max__c}"/>
               <apex:column value="{!c.tContact.InstallDate}"/>
                 <apex:inlineEditSupport event="ondblClick" 
                        showOnEdit="saveButton,cancelButton" hideOnEdit="editButton" />
            </apex:pageBlockTable>

            <apex:pageBlockSection collapsible="false" columns="2" id="paginsecblock">
      
                <!-- count of selected items -->
                <apex:outputLabel value="[{!selectedCount} records selected]" />            
                      
                <!-- next, previous and page info --> 
                <apex:outputPanel style="float:right">
                    <apex:commandLink action="{!doPrevious}" rendered="{!hasPrevious}" value="Previous" />
                    <apex:outputLabel rendered="{!NOT(hasPrevious)}" value="Previous"/>  
                    <apex:outputLabel value=" (page {!pageNumber} of {!totalPages}) "/>                                   
                    <apex:commandLink action="{!doNext}" rendered="{!hasNext}" value="Next" />
                    <apex:outputLabel rendered="{!NOT(hasNext)}" value="Next"/>
                </apex:outputPanel>
                
            </apex:pageBlockSection>
            </apex:pageBlockSection> 

        </apex:pageBlock> 
        
         
 
<apex:pageBlock id="configblock">
<apex:pageBlockSection title="Configuration Option" columns="2" id="configsecblock">

  <apex:pageBlockSectionItem id="configexpire">
   <apex:outputLabel value="Expiry Term:" for="expireterm"/> 
   <apex:selectList value="{!ExpireTerms}" multiselect="false" size="1" id="expterms">
                <apex:selectOption itemValue="0" itemLabel="--none--" id="exptermsnon"/>
                <apex:selectOption itemValue="1" itemLabel="1 Year"/>
                <apex:selectOption itemValue="3" itemLabel="3 Year"/>
                <apex:selectOption itemValue="5" itemLabel="5 Year"/>
    </apex:selectList>
   </apex:pageBlockSectionItem> 
   
   <apex:pageBlockSectionItem id="configexpiredate">
    <apex:outputLabel value="Expiry Date:"/>
   <apex:inputField value="{!GetExpireDate.Expire_Date__c}" id="expredate"/>
   </apex:pageBlockSectionItem> 
   
   <apex:pageBlockSectionItem id="configincumbent">        
    <apex:outputLabel value="Incumbent Reseller"></apex:outputLabel>        
    <!--apex:inputCheckbox value="{!IncumbentReseller}"/-->
    <apex:selectList value="{!IncumbentReseller}" multiselect="false" size="1" id="incumbentReseller">
                <apex:selectOption itemValue="No" itemLabel="No" />
                <apex:selectOption itemValue="Yes" itemLabel="Yes" />             
    </apex:selectList>   
   </apex:pageBlockSectionItem>  
   
   <apex:pageBlockSectionItem id="configeducation"> 
    <apex:outputLabel value="Education"></apex:outputLabel>       
    <!--apex:inputCheckbox value="{!Education}"/-->
    <apex:selectList value="{!Education}" multiselect="false" size="1" id="Education">
                <apex:selectOption itemValue="None" itemLabel="None" />
                <apex:selectOption itemValue="K-12" itemLabel="K-12" />
                <apex:selectOption itemValue="Higher-Ed" itemLabel="Higher-Ed" />               
    </apex:selectList> 

   </apex:pageBlockSectionItem>  

     <apex:pageBlockSectionItem id="configreseller"> 
    <apex:outputLabel value="Reseller"></apex:outputLabel>     
    <apex:inputField value="{!GetReseller.Primary_Reseller__c}" id="resler" /> 
    </apex:pageBlockSectionItem>

   <apex:pageBlockSectionItem id="configdistrbutor"> 
    <apex:outputLabel value="Distributor"></apex:outputLabel>        
    <apex:inputField value="{!GetDistributor.Primary_Distributor__c}" id="distbtr"/>  
   </apex:pageBlockSectionItem>    
   
   <apex:pageBlockSectionItem id="configopport"> 
    <apex:outputLabel value="Opportunity"></apex:outputLabel>        
    <apex:inputField value="{!GetOpportunity.Opportunity__c}" id="existopp"/>  
   </apex:pageBlockSectionItem>
   
    <apex:pageBlockSectionItem id="confignewopp"> 
    <apex:outputLabel value="New Opportunity"></apex:outputLabel>        
    <apex:inputField value="{!GetNewOpportunity.New_Opportunity__c}" id="newopp"/>  
   </apex:pageBlockSectionItem>    
   
   <apex:pageblockSectionItem id="configMonthlyQuote"> 
       <apex:outputLabel value="Generate Monthly SKU's"></apex:outputLabel>
       <apex:inputCheckbox value="{!monthly_quote}" id="monthlyQuote"/>
   </apex:pageblockSectionItem> 
       
</apex:pageBlockSection>
</apex:pageBlock> 
</apex:form>  
 
</apex:page>


Hi,

  I created a page redirect inside controller. Below highlited is the code to call page redirect. I am redirect the page to opporunity after data is saved. 
  
 Please suggest me how to modify its not working

// Store Selected Records to Object/Table
public void processSelected() {
    Integer currentPageNumber = setCon.getPageNumber();
    selectedAssets = new List<Asset>();
    list<Temp_Assets__c> TempAssetList = new list<Temp_Assets__c>(); 
       
     
     setCon.setpageNumber(1);
    

while(true){
    List<Asset>  TempAssetLists = (List<Asset>)setCon.getRecords();
    for(Asset assetIns : TempAssetLists  ) {
          if(this.selectedContactIds.contains(assetIns.Id)){
             selectedAssets.add(assetIns);
            
            
           }
     }
if(setCon.getHasNext()){
  setCon.next();
  }
  else{
  break;
  }
  

        /**********Added by Unnat*********************************/
        //below code should only execute if Expiry term has a value
        Date maxDate=Date.valueOf('2000-1-1');
        Date minDate;
       
        //Calculate the maximum Date off of the selected dates
     
        //finds the latest expiry date out of the selected assets
        for (Asset assets: selectedAssets) {
            if(assets.Service_End_Date_Max__c > maxDate) {
                maxDate=assets.Service_End_Date_Max__c;
            }
        }
        System.debug('== Latest Service end Date is:'+ maxDate);
        minDate = maxDate;
        for (Asset assets: selectedAssets) {
            if(minDate > assets.Service_End_Date_Max__c) {
                minDate=assets.Service_End_Date_Max__c;
            }
        }
        System.debug('== Least Service end Date is:'+ minDate);
       
         
        //Validations
        if ((selectedAssets.size() < 1 ) || (expireTerms == '0' && GetExpireDate.Expire_Date__c== null )|| (expireTerms != '0' && GetExpireDate.Expire_Date__c!= null ) || (GetDistributor.Primary_Distributor__c == null ) || (GetReseller.Primary_Reseller__c == null ) || (GetOpportunity.Opportunity__c==null && GetNewOpportunity.New_Opportunity__c== null ) || (GetOpportunity.Opportunity__c!=null && GetNewOpportunity.New_Opportunity__c!= null )|| (GetExpireDate.Expire_Date__c < maxDate )) {
        //Validates that atleast one of the assets is selected from the install base
        if(selectedAssets.size() < 1 ){
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error,'Please select atleast one Asset to renew from the Install Base.'));
        }
        //Validates that atleast one of the Expiry Dates needs to have a value
        if(expireTerms == '0' && GetExpireDate.Expire_Date__c== null ){
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error,'Please enter the Expiry Term or Expiry Date for the selected Assets.'));
        }
        //Valation that only of the Expirty Dates can have a value
        else if(expireTerms != '0' && GetExpireDate.Expire_Date__c!= null ){
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error,'You can enter a value either in Expiry Date or Expiry Term, but not in both.'));
        }
        //Validation that the Distributor Name is required
        if(GetDistributor.Primary_Distributor__c == null ){
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error,'Please enter a value in Distributor'));
        }
        //Validation that Reseller Name is required
        if(GetReseller.Primary_Reseller__c == null ){
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error,'Please enter a value in Reseller'));
        }
        //Validation that atleast one Opportunity needs to have a value
        if(GetOpportunity.Opportunity__c==null && GetNewOpportunity.New_Opportunity__c== null ){
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error,'Please enter a value in either of the Opportunity'));
        }
        //Validation that only one of the Opportunities can have a value
        else if(GetOpportunity.Opportunity__c!=null && GetNewOpportunity.New_Opportunity__c!= null ){
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error,'You can enter a value either in Opportunity or New Opportunity, but not in both.'));
        }
        //Validation that will check if the Expiry Date has value less than the selected Asset Service End Date
        if(GetExpireDate.Expire_Date__c < maxDate ){
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error,'Expiry Date that you entered is lower than Service End Date of the Asset'));
        }
        }
        else {
        //below code should only execute if Expiry term has a value
        //Date maxDate=Date.valueOf('2000-1-1');
        //Calculate the maximum Date off of the selected dates
       
        if (ExpireTerms !=null) {
        System.debug('== Expire Terms has a value');
       
            //There will be another condition to add the expiry term to the latest expiry date
            //String a='1 Year';
            System.debug('== ExpireTerms is: '+ ExpireTerms);
            if (ExpireTerms=='1') {
                System.debug('== First if condition');
                maxDate=maxDate.addYears(1);
            }
            else if (ExpireTerms == '3') {
            System.debug('== Second if condition');
                maxDate=maxDate.addYears(3);
            }
            else if (ExpireTerms == '5') {
            System.debug('== third if condition');
                maxDate=maxDate.addYears(5);
            }
            else {
                maxDate= GetExpireDate.Expire_Date__c;
            }
        }
        else {
        System.debug('== Else condition');
            maxDate= GetExpireDate.Expire_Date__c;  
        }
        System.debug('== Max Date is: ' + maxDate);
        Integer totalDays = minDate.daysBetween(maxDate);
        System.debug('== Total days difference is: '+ totalDays);
        /****************Completed by Unnat*****************************/
       
        //checks if the Monthly Quote is going to be more than 36 months and Monthly Quote Checkbox is selected
        /*if (totalDays > 1080 && Monthly_Quote == true ) {
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error,'Since the Renewals in Months is more than 3 years, please uncheck the Monthly Quote checkbox'));
        }
        else {*/       
            System.debug('=- after the if condition');          
            Account ResellerAct;
            Account DistributorAct; 
            Opportunity Oppt;          
                               
            for(Asset Act : selectedAssets)
            {              
                Temp_Assets__c TempAsset = new Temp_Assets__c();
                TempAsset.Name = 'Sudhir';
                TempAsset.AccountId__c = Act.AccountId;
                TempAsset.Product__c = Act.Product2Id;
                //Added by Unnat
                TempAsset.Product_lookup__c= Act.Product2Id;
                TempAsset.Asset_Id__c = Act.Id;
                TempAsset.Serial_Number__c = Act.SerialNumber;
                TempAsset.Last_Contract_Number__c = Act.last_contract_number__c;
                TempAsset.Service_Start_Date__c = Act.Service_Start_Date_Min__c;
               
                //TempAsset.Service_End_Date__c = Act.Service_End_Date_Max__c;
                /***************Added by Unnat********************************************/
                TempAsset.Opp_Close_Date__c = minDate;
                TempAsset.Monthly_Quote__c = Monthly_Quote;
                System.debug('=- Monthly Quote is: ' + monthly_Quote);
               
                if (Act.Service_End_Date_Max__c != null) {
                    TempAsset.Service_End_Date__c = Act.Service_End_Date_Max__c;
                }
                else {
                    TempAsset.Service_End_Date__c = Act.InstallDate;
                }
               
                TempAsset.Install_Date__c = Act.InstallDate; 
                System.debug ('==== Reseller id is: '+ GetReseller.Primary_Reseller__c);
                TempAsset.Reseller__c = GetReseller.Primary_Reseller__c;
                TempAsset.Distributor__c = GetDistributor.Primary_Distributor__c;
               
                /****************Commented by Unnat****************************************************************************
               
                If (GetReseller.AccountId <> NULL)
                {     
                ResellerAct = [ SELECT Id FROM Account WHERE ID = :GetReseller.Primary_Reseller__c Limit 1];
                TempAsset.Reseller__c = ResellerAct.Id;     
                 System.debug ('==== Reseller id 2 is: '+ ResellerAct.Id);       
                }
              
                If (GetDistributor.AccountId <> NULL )
                {
                DistributorAct = [ SELECT Id FROM Account WHERE ID = :GetDistributor.Primary_Distributor__c Limit 1];
                TempAsset.Distributor__c = DistributorAct.Id;
                }
               
                ****************Completed by Unnat *****************************************************************************/
                If ( GetOpportunity.Opportunity__c <> NULL )
                {
                Oppt = [SELECT Id FROM Opportunity WHERE ID = :GetOpportunity.Opportunity__c Limit 1];
                TempAsset.Existing_Opportunity__c = Oppt.Id;
                }               
                TempAsset.Incumbent_Reseller__c = IncumbentReseller;
                TempAsset.Education__c = Education;
                //TempAsset.Expiry_Date__c = GetExpireDate.Expire_Date__c;
                TempAsset.Expiry_Date__c= maxDate;
               
                TempAsset.New_Opportunity__c = GetNewOpportunity.New_Opportunity__c;
                TempAsset.Expiry_Term__c = ExpireTerms;
               
                /* Insert Bundel Checkbox Value */               
                if (this.selectedContactIds2.contains(Act.Id)){
                    bundsprt=true;
                }
                else {
                    bundsprt=false;
                }
               
               
                TempAsset.Bundle_Support__c = bundsprt;
                System.debug('== Bundle Value is: ' + bundsprt);
               
                             //Add the selected Assets to the List
                TempAssetList.add(TempAsset);
            }
               
            Insert TempAssetList;                           
           
           
       // } //end of if Condition for check of days more than 3 years
       }
        setCon.setpageNumber(currentPageNumber);
        Redirect();
    }
   
   public pagereference Redirect()
   {
     String optyURL2 = 'https://cs20.salesforce.com/006m0000002MqNf';
     PageReference pageref = new PageReference(optyURL2);   //<----- changed here
     pageref.setRedirect(true);  
     return pageref;
    }


Thanks
Sudhir

Hi, 

 I created a visual force page which has two option user can eithere select existing opportunity from pick list or He can create a new opportunity. 

  After saving the data page must redirect to selected or created opportunity. Please suggest me how to implement 

Below is the visualforce page. 

 <apex:page controller="CCW_ContactPaginationController"  showHeader="true" sidebar="true" >
   
    <script type="text/javascript">

        /*
        *    function to handle checkbox selection
        */
        function doCheckboxChange(cb,itemId){

            if(cb.checked==true){
                aSelectItem(itemId);
            }
            else{
                aDeselectItem(itemId);
            }

        }
        function doCheckboxChange2(cb,itemId){

            if(cb.checked==true){
                aSelectItem2(itemId);
            }
            else{
                aDeselectItem2(itemId);
            }

        }       
       

    </script>
<!-- Using apex:pageMessages instead  
<script type="text/javascript">
function Validation()
{
  var val   = document.getElementById('{!$Component.RenewalForm.configblock.configsecblock.confignewopp.newopp}').value; 
  var oval  = document.getElementById('{!$Component.RenewalForm.configblock.configsecblock.configopport.existopp}').value; 
  var edate = document.getElementById('{!$Component.RenewalForm.configblock.configsecblock.configexpiredate.expredate}').value; 
  var eterm = document.getElementById('{!$Component.RenewalForm.configblock.configsecblock.configexpire.expterms}').value;
  var eresr = document.getElementById('{!$Component.RenewalForm.configblock.configsecblock.configreseller.resler}').value;
  var edstb = document.getElementById('{!$Component.RenewalForm.configblock.configsecblock.configdistrbutor.distbtr}').value;
 
  if ( edate == '' && eterm == '0' ) {
    alert('Enter either expire date or select expite term');
    return false;
     }
  else if ( edate != '' && eterm != '0' )
   {
    alert('Enter either expire date or select expite term');
    return false;
   } 
  else if ( eresr == '' && edstb == '' )
   {
    alert('Enter reseller and distributor details');
    return false;
   }
  else if ( eresr == '' && edstb != ''  )
   {
    alert('Enter reseller details');
    return false;
   }
  else if ( eresr != '' && edstb == '' )
   {
    alert('Enter distributor details');
    return false;
   }
  else if ( val == '' && oval == '')
  {
    alert('Enter either existing opportunity or new opporutnity');
    return false;
    }
  else if ( val != '' && oval != '')
  {
     alert('Enter either existing opportunity or new opporutnity');
     return false;
     }
  else    
     alert('Please check row in Install Based Report to saved records');
     return true;    
  }
</script>
Done commenting the javaScript code -->
  
<apex:sectionHeader subtitle="Create Renewal Quote" title="Meru Networks"/>

<apex:form id="RenewalForm">
<apex:pageBlock id="filterblock">
<apex:pageBlockSection title="Filters" columns="3" id="filterblocksection">
<apex:inputField value="{!GetAccount.AccountId}" label="Account"/>
<apex:inputField value="{!GetContract.Name}" label="Contract" required="false"/>
<apex:commandButton action="{!fetch_data}" value="Fetch Data"></apex:commandbutton>

</apex:pageBlockSection>
</apex:pageBlock>       
                
       
    <apex:pageBlock id="reportblock">
        <apex:pageMessages />
        <apex:pageBlockButtons id="reportbutton">
        <apex:commandButton value="Save Records" action="{!processSelected}"  />
        <apex:commandButton value="Cancel" onclick="window.top.close()"/>
        </apex:pageBlockButtons>
      
        <!-- handle selected item -->
        <apex:actionFunction name="aSelectItem" action="{!doSelectItem}" rerender="mpb">
            <apex:param name="contextItem" value="" assignTo="{!contextItem}"/>
        </apex:actionFunction>
       
        <apex:actionFunction name="aSelectItem2" action="{!doSelectItem2}" rerender="mpb">
            <apex:param name="contextItem2" value="" assignTo="{!contextItem2}" />
        </apex:actionFunction>
       
        <!-- handle deselected item -->
        <apex:actionFunction name="aDeselectItem" action="{!doDeselectItem}" rerender="mpb">
            <apex:param name="contextItem" value="" assignTo="{!contextItem}"/>
        </apex:actionFunction>
       
        <apex:actionFunction name="aDeselectItem2" action="{!doDeselectItem2}" rerender="mpb">
            <apex:param name="contextItem2" value="" assignTo="{!contextItem2}"/>
        </apex:actionFunction>
            
       <apex:pageBlockSection title="Install Base" id="mpb" collapsible="true" columns="1" >

            <!-- table of data -->
            <apex:pageBlockTable title="Assets" value="{!Contacts}" var="c" id="reportblocktable" >
                <apex:column >
                    <apex:facet name="header">Action</apex:facet>
                    <apex:inputCheckbox value="{!c.IsSelected}" onclick="doCheckboxChange(this,'{!c.tContact.Id}')"/>
                </apex:column>
                <apex:column >
                    <apex:facet name="header">Bundle Support</apex:facet>
                    <apex:inputCheckbox value="{!c.BundelSelected}" onclick="doCheckboxChange2(this,'{!c.tContact.Id}')"/>
                 </apex:column>
                <apex:column value="{!c.tContact.AccountId}"/>
                <apex:column value="{!c.tContact.Product2Id}"/>
                <apex:column value="{!c.tContact.SerialNumber}"/>
                <apex:column value="{!c.tContact.last_contract_number__c}"/>
                <apex:column value="{!c.tContact.Service_Start_Date_Min__c}"/>
               <apex:column value="{!c.tContact.Service_End_Date_Max__c}"/>
               <apex:column value="{!c.tContact.InstallDate}"/>
                 <apex:inlineEditSupport event="ondblClick"
                        showOnEdit="saveButton,cancelButton" hideOnEdit="editButton" />
            </apex:pageBlockTable>

            <apex:pageBlockSection collapsible="false" columns="2" id="paginsecblock">
     
                <!-- count of selected items -->
                <apex:outputLabel value="[{!selectedCount} records selected]" />           
                     
                <!-- next, previous and page info -->
                <apex:outputPanel style="float:right">
                    <apex:commandLink action="{!doPrevious}" rendered="{!hasPrevious}" value="Previous" />
                    <apex:outputLabel rendered="{!NOT(hasPrevious)}" value="Previous"/> 
                    <apex:outputLabel value=" (page {!pageNumber} of {!totalPages}) "/>                                  
                    <apex:commandLink action="{!doNext}" rendered="{!hasNext}" value="Next" />
                    <apex:outputLabel rendered="{!NOT(hasNext)}" value="Next"/>
                </apex:outputPanel>
               
            </apex:pageBlockSection>
            </apex:pageBlockSection>

        </apex:pageBlock>
       
        

<apex:pageBlock id="configblock">
<apex:pageBlockSection title="Configuration Option" columns="2" id="configsecblock">

  <apex:pageBlockSectionItem id="configexpire">
   <apex:outputLabel value="Expiry Term:" for="expireterm"/>
   <apex:selectList value="{!ExpireTerms}" multiselect="false" size="1" id="expterms">
                <apex:selectOption itemValue="0" itemLabel="--none--" id="exptermsnon"/>
                <apex:selectOption itemValue="1" itemLabel="1 Year"/>
                <apex:selectOption itemValue="3" itemLabel="3 Year"/>
                <apex:selectOption itemValue="5" itemLabel="5 Year"/>
    </apex:selectList>
   </apex:pageBlockSectionItem>
  
   <apex:pageBlockSectionItem id="configexpiredate">
    <apex:outputLabel value="Expiry Date:"/>
   <apex:inputField value="{!GetExpireDate.Expire_Date__c}" id="expredate"/>
   </apex:pageBlockSectionItem>
  
   <apex:pageBlockSectionItem id="configincumbent">       
    <apex:outputLabel value="Incumbent Reseller"></apex:outputLabel>       
    <!--apex:inputCheckbox value="{!IncumbentReseller}"/-->
    <apex:selectList value="{!IncumbentReseller}" multiselect="false" size="1" id="incumbentReseller">
                <apex:selectOption itemValue="No" itemLabel="No" />
                <apex:selectOption itemValue="Yes" itemLabel="Yes" />            
    </apex:selectList>  
   </apex:pageBlockSectionItem> 
  
   <apex:pageBlockSectionItem id="configeducation">
    <apex:outputLabel value="Education"></apex:outputLabel>      
    <!--apex:inputCheckbox value="{!Education}"/-->
    <apex:selectList value="{!Education}" multiselect="false" size="1" id="Education">
                <apex:selectOption itemValue="None" itemLabel="None" />
                <apex:selectOption itemValue="K-12" itemLabel="K-12" />
                <apex:selectOption itemValue="Higher-Ed" itemLabel="Higher-Ed" />              
    </apex:selectList>

   </apex:pageBlockSectionItem> 

     <apex:pageBlockSectionItem id="configreseller">
    <apex:outputLabel value="Reseller"></apex:outputLabel>    
    <apex:inputField value="{!GetReseller.Primary_Reseller__c}" id="resler" />
    </apex:pageBlockSectionItem>

   <apex:pageBlockSectionItem id="configdistrbutor">
    <apex:outputLabel value="Distributor"></apex:outputLabel>       
    <apex:inputField value="{!GetDistributor.Primary_Distributor__c}" id="distbtr"/> 
   </apex:pageBlockSectionItem>   
  
   <apex:pageBlockSectionItem id="configopport">
    <apex:outputLabel value="Opportunity"></apex:outputLabel>       
    <apex:inputField value="{!GetOpportunity.Opportunity__c}" id="existopp"/> 
   </apex:pageBlockSectionItem>
  
    <apex:pageBlockSectionItem id="confignewopp">
    <apex:outputLabel value="New Opportunity"></apex:outputLabel>       
    <apex:inputField value="{!GetNewOpportunity.New_Opportunity__c}" id="newopp"/> 
   </apex:pageBlockSectionItem>   
  
   <apex:pageblockSectionItem id="configMonthlyQuote">
       <apex:outputLabel value="Monthly Quote"></apex:outputLabel>
       <apex:inputCheckbox value="{!monthly_quote}" id="monthlyQuote"/>
   </apex:pageblockSectionItem>
      
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form> 

</apex:page>


Let me know if  you need controller will past the code.

Thanks
Sudhir

Hi, 

 Can we close visualforce page after button click.  We have a button which will save records after saving records page needs to be closed. 
  
  Please suggest me how to implement 

Thanks

Sudhir

Hi, 

  I wrote a trigger below to update opportuntiy from custom object based on condition but is not updating please help

 Code below highlighted in bold is not updating

trigger Temp_Asset2_Opp on Temp_Assets__c (after insert )
{
    List<OpportunityLineItem> OppLineItems = new List<OpportunityLineItem>();
   
    List<Temp_Assets__c> CurrentAssetOpp = [Select Id, Name, Asset_Id__c, Serial_Number__c, AccountId__c, Product__c, Service_Start_Date__c,
                                              Service_End_Date__c ,Install_Date__c ,Reseller__c,Distributor__c ,
                                              Incumbent_Reseller__c,Education__c,Expiry_Date__c,Existing_Opportunity__c,
                                              New_Opportunity__c,Expiry_Term__c,Bundle_Support__c, X5_Year_SKU_Code__c, X3_Year_SKU_Code__c,
                                              X1_Year_SKU_Code__c, Monthly_SKU_Code__c, X5_year_SKU__c ,X3_year_SKU__c, X1_year_SKU__c,
                                              Total_in_Months__c, Support_Only_5_Year_SKU__c, Support_Only_3_Year_SKU__c, Support_Only_1_Year_SKU__c,
                                              Support_Only_Monthly_SKU__c, DaysRemaining_Months__c
                                              From Temp_Assets__c
                                              Where CreatedById = :userinfo.getUserId() Limit 1];
   
    List<Temp_Assets__c> CurrentAssetOppLine = [Select Id, Name, Asset_Id__c, Serial_Number__c, AccountId__c, Product__c, Service_Start_Date__c,
                                                Service_End_Date__c ,Install_Date__c ,Reseller__c,Distributor__c ,
                                                Incumbent_Reseller__c,Education__c,Expiry_Date__c,Existing_Opportunity__c,
                                                New_Opportunity__c,Expiry_Term__c,Bundle_Support__c, X5_Year_SKU_Code__c, X3_Year_SKU_Code__c,
                                                X1_Year_SKU_Code__c, Monthly_SKU_Code__c, X5_year_SKU__c ,X3_year_SKU__c, X1_year_SKU__c,
                                                Total_in_Months__c, Support_Only_5_Year_SKU__c, Support_Only_3_Year_SKU__c, Support_Only_1_Year_SKU__c,
                                                Support_Only_Monthly_SKU__c, DaysRemaining_Months__c
                                                From Temp_Assets__c
                                                Where CreatedById = :userinfo.getUserId()];

    Pricebook2 prBook= [select id from Pricebook2 where Name=: 'NAM Price Book'];
    RecordType renewal_RT = [Select id, Name, sObjectType from RecordType where sObjectType= 'Opportunity' and Name = 'Renewal Opportunity' ];
   
   Opportunity Opp = new Opportunity();
  
   for ( Temp_Assets__c TA : CurrentAssetOpp )
   {   
     // If New Opportunity is Created 
    if ( TA.Existing_Opportunity__c == NULL && TA.New_Opportunity__c != NULL )   
     {
            // Insert Opportunity with all mandatory fields       
             Opp.Name      = TA.New_Opportunity__c;            
             Opp.Type      = 'Existing Customer';
             Opp.AccountId = TA.AccountId__c;
             Opp.CloseDate =  system.today().addDays(+30); // default Sysdate + 30
             Opp.Government_Contract__c = 'None';
             Opp.Renewal_Opportunity__c = 'Yes';
             Opp.StageName = 'Renewal';
             //Opp.Lost_Reason__c = 'Other'; // not required
             Opp.Primary_Competitor__c = 'No Competitor';
             Opp.ForecastCategoryName = 'Pipeline';
             Opp.LeadSource = 'Renewal';
             Opp.Primary_Reseller__c    = TA.Reseller__c;
             Opp.Primary_Distributor__c = TA.Distributor__c;
             Opp.Renewal_Incumbant_Reseller__c = TA.Incumbent_Reseller__c;
             Opp.Renewal_K_12__c   =  TA.Education__c;
             //Assigning the new Opportunity to the Renewal Record Type
             opp.recordtypeId = renewal_RT.id;
            
          Insert Opp;
      }
    
     
    if ( TA.Existing_Opportunity__c == NULL && TA.New_Opportunity__c != NULL )   
     {
        List<Opportunity> OpptUp = [select Id from Opportunity where id =  :TA.Existing_Opportunity__c ];       
       
         for ( Opportunity OppUpd : OpptUp ) {
                OppUpd.test__c = 'Sudhir';
                OppUpd.Primary_Reseller__c    = TA.Reseller__c;
                OppUpd.Primary_Distributor__c =  TA.Distributor__c;
                OppUpd.Renewal_Incumbant_Reseller__c =  TA.Incumbent_Reseller__c;
                OppUpd.Renewal_K_12__c   =  TA.Education__c;
                //change the RecordType of this existing Opportunity to Renewal Opportunity Record Type
                OppUpd.recordtypeId = renewal_RT.id;                  
            }  
         Update OpptUp;     

      }   
          
    }    
     
List<Temp_Assets__c> TempAsset = [SELECT Id From Temp_Assets__c Where CreatedById = :userinfo.getUserId()];
//delete TempAsset ;

}

Thanks

Sudhir