• JosephJ
  • NEWBIE
  • 60 Points
  • Member since 2013

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 15
    Questions
  • 48
    Replies
I am trying to use a different components in a VF page.At present,the component is made only on Account object.The requirement is to make it for other standard objects like Contacts,Leads etc.

How will this go ?  Thanks in advance. James


       === Page ===
    
<apex:page standardController="Account">  <!-- This is for Account,how to do it for other objects ? -->
      <c:MadoleChartComponent />
     </apex:page>

     ==== Component ===

<apex:component Controller="HighchartsController">
       <script src="https://code.jquery.com/jquery-1.11.1.min.js"></script>
       <script src="https://code.highcharts.com/highcharts.js"></script>
       <script src="https://code.highcharts.com/modules/exporting.js"></script>

      <div id="container" style="min-width: 310px; height: 400px; margin:0 auto"></div>

        <script>
            pieOrdinate = {!X};
           // pieOrdinate = ServerStr.split(',');
             $(function () {
             $('#container').highcharts({
             title: {
             text: 'Chart showing opportunities'
        },
        xAxis:{
                categories: ['Jan','Feb','Mar','Apr','May','Jun','July','Aug','Sept','Oct','Nov','Dec']
            },
              labels: {
              items: [{
              html: 'Opportunities',
              style: {
                    left: '50px',
                    top: '18px',
                    color: (Highcharts.theme && Highcharts.theme.textColor) || 'black'
                }
            }]
        },
        series: [ {
            type: 'column',
            name: 'Indian Railways',
            data: {!str}
            //data:[2,3,4,5,6]
        },
         {
            type: 'spline',
            name: 'Monthly Sales', // Average
           // data: [3, 2.67, 3, 6.33, 3.33],  
           data :{!bar},
            marker: {
                lineWidth: 2,
                lineColor: Highcharts.getOptions().colors[3],
                fillColor: 'white'
            }
        },
        {
            type: 'pie',
            name: 'Total consumption',
            data: [ {
                name: 'Lost',
                //y:23,
                y :parseInt(pieOrdinate[0]),
                sliced:true,
                selected:true,
                color: Highcharts.getOptions().colors[1] // Opp's Lost color
              },
               {
                name: 'Won',
                y:parseInt(pieOrdinate[1]),
                color: Highcharts.getOptions().colors[2] // Opp's won color
              }],
               center: [100, 80],
               size: 100,
               showInLegend: false,
               dataLabels:
               {
                 enabled:true
               }
             }]
         });
      });
      </script>
     </apex:component>


I tried each and every possibility to know where i'm going wrong but still no luck. My issue is my search (i.e. filter) is working on Subject,Status and Date field for Task object .

Now i want to search for one more column which is "OwnerId" . I know it can be done using if condition something like below  but what should be "IF condition " to get to the goal ?

if (logical condition  to filter by owner) {
    qStr + ' and OwnerId in :ownerIds';


I'm really paralyzed and need help.

public class PagingTasksController1{

    public List<Task> Tasks;

   
    public Task del;
    public Task taskDel;
    public Integer CountTotalRecords{get;set;}
    public String QueryString {get;set;}
    public Integer OffsetSize = 0;
    private Integer QueryLimit =3 ;
    public List<Task> lstTasks {get;set;}
    public String searchText {get;set;}
    public String rowIndex {get;set;}
//   public List<Task> attendeeList {get;set;}
    public Date mydate;
    public Integer totalCount {get;set;}
    public string sortField = 'Subject';  // default sort column
    private string sApplySOQL = '';
   public List<Task> delattendeeList {get;set;}

    public List<Task> delAttendees {get; set;}

    public PagingTasksController1(ApexPages.StandardController controller) {

     taskDel= (Task)controller.getRecord();
     Tasks = [Select id,Subject,Status,ActivityDate from Task where OwnerId =: taskDel.Id];
    // this.Tasks=Tasks[0];
     totalCount = Tasks.size();

     delattendeeList = new List<Task>();
     delattendees = new List<Task>();
}


// the current sort direction. defaults to ascending
    public String sortDir {
        get  { if (sortDir == null) {  sortDir = 'asc'; } return sortDir;  }
        set;
    }

    // the current field to sort by. defaults to role name
    public String getsortField() {
        return sortField;
    }

    // the current field to sort by.
    public void setsortField(string value) {
        sortField = value;
    }
            
    // toggles the sorting of query from asc<-->desc
    public void toggleSort() {
        // simply toggle the direction
        sortDir = sortDir.equals('asc') ? 'desc' : 'asc';
      
        integer iIndex = sApplySOQL.indexOf('Order By');
        if (iIndex > -1){
          sApplySOQL = sApplySOQL.substringBefore('Order By');
          sApplySOQL = sApplySOQL + ' Order By ' + sortField + ' ' + sortDir +  ' limit ' + QueryLimit + ' offset ' + OffsetSize;
        }
        tasks = Database.query(sApplySOQL );
    }
  
    public PagingTasksController1 (){
        //CountTotalRecords= [select count() from Task];
        //String qStr2= '7/23/2014';
          
    }

   public List<Task> getTasks(){
        if(tasks == null){
            tasks = new List<Task>();
        }
        return tasks;
    }

    public void findTasks(){
        String qStr2 = 'Select count() from Task where Subject like \'%'+searchText+'%\' OR Status like \'%'+searchText+'%\'';
        CountTotalRecords = Database.countQuery(qStr2);
        queryTasks();
    }

    public void  queryTasks(){
        
        String qStr2= searchText;
        String strnormal = '';
        try{
             mydate = date.parse(qStr2);
        }catch(Exception e)
        { }
           
        String strDate = '';
        if(mydate != null) {
         // strnormal = String.valueOf(mydate );
          String[] qstr3 = String.valueOf(mydate).split(' ',2); 
          strDate = ' ActivityDate =  '+ qstr3[0] + ' ';
        }else{
       
           strDate  =  'Subject like \'%'+searchText +'%\' OR Status like \'%' +searchText+ '%\' Order By '  + sortField;
        }
        String qStr = 'Select OwnerId,Subject,Status,ActivityDate from Task where '  + strDate   ;

         System.debug(qStr );
           
//        String qStr = 'Select OwnerId,Subject,Status,Priority from Task where Subject like \'%'+searchText+'%\' OR Status like \'%'+searchText+ '%\' Order By ' + sortField;

       
       
        sApplySOQL = qStr;
      
        tasks = Database.query(sApplySOQL );
        //tasks.sort();

    }

    public Boolean getDisablePrevious(){
        if(OffsetSize>0){
            return false;
        }
        else return true;
    }

    public Boolean getDisableNext() {
        if (OffsetSize + QueryLimit < countTotalRecords){
            return false;
        }
        else return true;
    }

    public PageReference Next() {
        OffsetSize += QueryLimit;
        queryTasks();
        return null;
    }

    public PageReference Previous() {
        OffsetSize -= QueryLimit;
        queryTasks();
        return null;
    }

      public PageReference save() {
        update tasks;
        return ApexPages.CurrentPage();
     }
    
    public void deleteRow(){

         rowIndex = String.valueOf(ApexPages.currentPage().getParameters().get('rowIndex'));
         System.debug('rowIndex ------------'+rowIndex );
         if(rowIndex!=null)
         {
         Task check=[Select id from Task where id=: rowIndex];
         System.debug('row to be deleted ' + check);
         delete check;
         Tasks=[Select Subject,Status,ActivityDate,OwnerId from Task ];
         update Tasks;
         }
     }
     
  }
Experts please help.

The problem that i'm facing is my my pagination is not working . The QueryLimit does not mark fare ,the table simply searches the word and displays.

Also for "Deleting" records , it is giving me :  List index out of bounds: 4 Error is in expression '{!deleteRow}' in component <apex:commandButton> in page new_test_task_assignment: Class.PagingTasksController1.deleteRow: line 152,.

I'm just messed and struggling.Please help .Thanks in advance .James


public class PagingTasksController1{

    public List<Task> Tasks;
    public Task del;
    public Task taskDel;
    public Integer CountTotalRecords{get;set;}
    public String QueryString {get;set;}
    public Integer OffsetSize = 0;
    private Integer QueryLimit =3 ;
    public List<Task> lstTasks {get;set;}
    public String searchText {get;set;}
    public Integer rowIndex {get;set;}
    public Date mydate;
    public Integer totalCount {get;set;}
    public string sortField = 'Subject';  // default sort column
    private string sApplySOQL = '';
    public List<Task> delattendeeList {get;set;}

    public List<Task> delAttendees {get; set;}
    public PagingTasksController1(ApexPages.StandardController controller) {

     taskDel= (Task)controller.getRecord();
     Tasks = [Select id,Subject,Status,ActivityDate from Task where OwnerId =: taskDel.Id];
    // this.Tasks=Tasks[0];
     totalCount = Tasks.size();

     delattendeeList = new List<Task>();
     delattendees = new List<Task>();
}


// the current sort direction. defaults to ascending
    public String sortDir {
        get  { if (sortDir == null) {  sortDir = 'asc'; } return sortDir;  }
        set;
    }

    // the current field to sort by. defaults to role name
    public String getsortField() {
        return sortField;
    }

    // the current field to sort by.
    public void setsortField(string value) {
        sortField = value;
    }
            
    // toggles the sorting of query from asc<-->desc
    public void toggleSort() {
        // simply toggle the direction
        sortDir = sortDir.equals('asc') ? 'desc' : 'asc';
      
        integer iIndex = sApplySOQL.indexOf('Order By');
        if (iIndex > -1){
          sApplySOQL = sApplySOQL.substringBefore('Order By');
          sApplySOQL = sApplySOQL + ' Order By ' + sortField + ' ' + sortDir +  ' limit ' + QueryLimit + ' offset ' + OffsetSize;
        }
        tasks = Database.query(sApplySOQL );
    }
 
    public PagingTasksController1 (){
        //CountTotalRecords= [select count() from Task];
        //String qStr2= '7/23/2014';
          
    }
   public List<Task> getTasks(){
        if(tasks == null){
            tasks = new List<Task>();
        }
        return tasks;
    }
   public void findTasks(){
        String qStr2 = 'Select count() from Task where Subject like \'%'+searchText+'%\' OR Status like \'%'+searchText+'%\'';
        CountTotalRecords = Database.countQuery(qStr2);
        queryTasks();
    }
   public void  queryTasks(){
        
        String qStr2= searchText;
        String strnormal = '';
        try{
             mydate = date.parse(qStr2);
        }catch(Exception e)
        { }
           
        String strDate = '';
        if(mydate != null) {
         // strnormal = String.valueOf(mydate );
          String[] qstr3 = String.valueOf(mydate).split(' ',2); 
          strDate = ' ActivityDate =  '+ qstr3[0] + ' ';
        }else{
              strDate  =  'Subject like \'%'+searchText +'%\' OR Status like \'%' +searchText+ '%\' Order By '  + sortField;
        }
        String qStr = 'Select OwnerId,Subject,Status,ActivityDate from Task where '  + strDate   ;
        System.debug(qStr );
        sApplySOQL = qStr;
        tasks = Database.query(sApplySOQL );
        //tasks.sort();

    }
  public Boolean getDisablePrevious(){
        if(OffsetSize>0){
            return false;
        }
        else return true;
    }
  public Boolean getDisableNext() {
        if (OffsetSize + QueryLimit < countTotalRecords){
            return false;
        }
        else return true;
    }
  public PageReference Next() {
        OffsetSize += QueryLimit;
        queryTasks();
        return null;
    }
  public PageReference Previous() {
        OffsetSize -= QueryLimit;
        queryTasks();
        return null;
    }
  public PageReference save() {
        update tasks;
        return ApexPages.CurrentPage();
     }
    
  public void deleteRow(){

         rowIndex = Integer.valueOf(ApexPages.currentPage().getParameters().get('rowIndex'));
         System.debug('row to be deleted ' + rowIndex );
         System.debug('row item to be deleted '+ Tasks[rowIndex]);
         del = Tasks.remove(rowIndex);
         delattendeeList.add(del);
     }
     
  }
My arrow sorting is not working. Pressing my head from hours.Any issue with my query ? It is Urgent.

public class PagingTasksController1{

    public List<Task> tasks;
    public Integer CountTotalRecords{get;set;}
    public String QueryString {get;set;}
    public Integer OffsetSize = 0;
    private Integer QueryLimit = 10;
    public List<Task> lstTasks;
    public String searchText {get;set;}
 
    public Date mydate;
    public string sortField = 'Subject';  // default sort column
    private string sApplySOQL = '';

// the current sort direction. defaults to ascending
    public String sortDir {
        get  { if (sortDir == null) {  sortDir = 'asc'; } return sortDir;  }
        set;
    }

    // the current field to sort by. defaults to role name
    public String getsortField() {
        return sortField;
    }

    // the current field to sort by.
    public void setsortField(string value) {
        sortField = value;
    }
           
    // toggles the sorting of query from asc<-->desc
    public void toggleSort() {
        // simply toggle the direction
        sortDir = sortDir.equals('asc') ? 'desc' : 'asc';
     
        integer iIndex = sApplySOQL.indexOf('Order By');
        if (iIndex > -1){
          sApplySOQL = sApplySOQL.substringBefore('Order By');
          sApplySOQL = sApplySOQL + ' Order By ' + sortField + ' ' + sortDir +  ' limit ' + QueryLimit + ' offset ' + OffsetSize;
        }
        tasks = Database.query(sApplySOQL );
    }

    public PagingTasksController1 (){
        //CountTotalRecords= [select count() from Task];
         //String qStr2= '7/23/2014';
   
    }
    public List<Task> getTasks(){
        if(tasks == null){
            tasks = new List<Task>();
        }
        return tasks;
    }

    public void findTasks(){
        String qStr2 = 'Select count() from Task where Subject like \'%'+searchText+'%\' OR Status like \'%'+searchText+'%\'';
        CountTotalRecords = Database.countQuery(qStr2);
        queryTasks();
    }

    public void  queryTasks(){
       
        String qStr2= searchText;
        String strnormal = '';
        try{
             mydate = date.parse(qStr2);
        }catch(Exception e)
        { }
          
        String strDate = '';
        if(mydate != null) {
         // strnormal = String.valueOf(mydate );
          String[] qstr3 = String.valueOf(mydate).split(' ',2);
          strDate = ' ActivityDate =  '+ qstr3[0] + ' ';
        }else{
      
           strDate  =  'Subject like \'%'+searchText +'%\' OR Status like \'%' +searchText+ '%\'';
        }
        String qStr = 'Select OwnerId,Subject,Status, ActivityDate from Task where '  + strDate   ;

         System.debug(qStr );
          
      
        sApplySOQL = qStr;
     
        tasks = Database.query(sApplySOQL );
        //tasks.sort();

    }

    public Boolean getDisablePrevious(){
        if(OffsetSize>0){
            return false;
        }
        else return true;
    }

    public Boolean getDisableNext() {
        if (OffsetSize + QueryLimit < countTotalRecords){
            return false;
        }
        else return true;
    }

    public PageReference Next() {
        OffsetSize += QueryLimit;
        queryTasks();
        return null;
    }

    public PageReference Previous() {
        OffsetSize -= QueryLimit;
        queryTasks();
        return null;
    }

      public PageReference save() {
        update tasks;
        return ApexPages.CurrentPage();
     }
   
  }
I feel like I've wasted enough time tracking it down.Pretty simple thing.

I have a pageBlockTable. One of the links in it, lets me delete that row. After the row is deleted the table should be rerendered so you can see that it has been removed. Currently the record DOES get deleted, but the table is not rerendered. I was wondering if maybe the table is reloading before the record is actually deleteed, causing a 'race' condition type of situation? Anyway, below is the code. Feel free to point out what I am doing wrong.Thanks in advance


<apex:page controller="PagingTasksController1" docType="html-5.0">
    <apex:form >
        <apex:pageBlock title="Tasks" id="pgBlock">
           <apex:pageBlockButtons >
               <apex:commandButton action="{!save}" id="saveButton" value="Save"/>
               <apex:commandButton onclick="resetInlineEdit()" id="cancelButton" value="Cancel"/>
           </apex:pageBlockButtons>
 
        <apex:inlineEditSupport showOnEdit="saveButton, cancelButton"
                    hideOnEdit="editButton" event="ondblclick"
                    changedStyleClass="myBoldClass" resetFunction="resetInlineEdit"/>
 
          <apex:inputText id="searchBox" value="{!searchText}"/>
           <apex:commandButton value="Search" reRender="pgTable,pgBlock" action="{!findTasks}"/>
           <apex:pageBlockTable value="{!Tasks}" var="tsk" id="pgTable" >
          
                 
          <apex:column headerValue="Action" >
             <apex:outputLink value="{!URLFOR($Action.Task.Delete, tsk.id,['retURL'='/apex/New_Test_task_Assignment'])}"> Delete</apex:outputLink>
           </apex:column>

               
          <apex:column headerValue="Subject">
              <apex:facet name="header">
                    <apex:commandLink value="Subject" action="{!toggleSort}" rerender="pgTable" >
                    <apex:param name="sortField" value="Subject" assignTo="{!sortField}"/>
                    <apex:outputPanel rendered="{!BEGINS(sortField,'Subject')}">
                        &nbsp;<apex:image value="{!IF(sortDir = 'asc','/img/arrowDown.gif','/img/arrowUp.gif')}"/>
                    </apex:outputPanel>
                    </apex:commandLink>
                </apex:facet>    
              
                  <apex:outputField value="{!tsk.Subject}"/>
           </apex:column>
                 
           <apex:column headerValue="Status">
               <apex:facet name="header">
                    <apex:commandLink value="Status" action="{!toggleSort}" rerender="pgTable" >
                    <apex:param name="sortField" value="Status" assignTo="{!sortField}"/>
                    <apex:outputPanel rendered="{!BEGINS(sortField,'Status')}">
                        &nbsp;<apex:image value="{!IF(sortDir = 'asc','/img/arrowDown.gif','/img/arrowUp.gif')}"/>
                    </apex:outputPanel>
                    </apex:commandLink>
              </apex:facet>        
 
             <apex:outputField value="{!tsk.Status}"/>
         </apex:column>
                      
     </apex:pageBlockTable>
       <apex:pageBlockButtons >
                <apex:commandButton value="Previous" action="{!Previous}" rerender="pgTable,pgBlock"
                                    status="status" disabled="{!DisablePrevious}" />
                <apex:commandButton value="Next" action="{!Next}" reRender="pgTable,pgBlock"
                                    status="status" disabled="{!DisableNext}" />
                <apex:actionStatus id="status" startText="Please Wait..."/>
            </apex:pageBlockButtons>
        </apex:pageBlock>
    </apex:form>
     <apex:enhancedlist type="Activity" height="800" rowsPerPage="50" customizable="False"/>
</apex:page>
I'm facing a seious issue here for my query :

String qStr = 'Select OwnerId,Subject,Status,Priority from Task where Subject like \'%'+searchText+'%\' OR Status like \'%'+searchText+'%\' Order By Subject,Status limit ' + QueryLimit + ' offset ' + OffsetSize;

Now the issue is , i need to filter this by one more field called "ActivityDate " which is for Task object. The document says , LIKE operator works only on Strings and hence if i'm including OR ActivityDate like \'%'+searchText+'%\'  it will not work.. How can i get this ?  I'm stucked here.Thanks in advance.

public class PagingTasksController1{

    public List<Task> tasks;
    public Integer CountTotalRecords{get;set;}
    public String QueryString {get;set;}
    public Integer OffsetSize = 0;
    private Integer QueryLimit = 5;
    public List<Task> lstTasks;
    public String searchText {get;set;}

    public string sortField = 'Subject';  // default sort column
    private string sApplySOQL = '';

// the current sort direction. defaults to ascending
    public String sortDir {
        get  { if (sortDir == null) {  sortDir = 'asc'; } return sortDir;  }
        set;
    }

    // the current field to sort by. defaults to role name
    public String getsortField() {
        return sortField;
    }

    // the current field to sort by.
    public void setsortField(string value) {
        sortField = value;
    }
            
    // toggles the sorting of query from asc<-->desc
    public void toggleSort() {
        // simply toggle the direction
        sortDir = sortDir.equals('asc') ? 'desc' : 'asc';
      
        integer iIndex = sApplySOQL.indexOf('Order By');
        if (iIndex > -1){
          sApplySOQL = sApplySOQL.substringBefore('Order By');
          sApplySOQL = sApplySOQL + ' Order By ' + sortField + ' ' + sortDir;
        }
        tasks = Database.query(sApplySOQL );
    }
 
    public PagingTasksController1 (){
        //CountTotalRecords= [select count() from Task];
    }
   public List<Task> getTasks(){
        if(tasks == null){
            tasks = new List<Task>();
        }
        return tasks;
    }
    public void findTasks(){
        String qStr2 = 'Select count() from Task where Subject like \'%'+searchText+'%\' OR Status like \'%'+searchText+'%\'';
        CountTotalRecords = Database.countQuery(qStr2);
        queryTasks();
    }
    public void  queryTasks(){
        String qStr = 'Select OwnerId,Subject,Status,Priority from Task where Subject like \'%'+searchText+'%\' OR Status like \'%'+searchText+'%\' Order By Subject,Status limit ' + QueryLimit + ' offset ' + OffsetSize;
        sApplySOQL = qStr;
      
        tasks = Database.query(sApplySOQL );
        //tasks.sort();

    }
    public Boolean getDisablePrevious(){
        if(OffsetSize>0){
            return false;
        }
        else return true;
    }
    public Boolean getDisableNext() {
        if (OffsetSize + QueryLimit < countTotalRecords){
            return false;
        }
        else return true;
    }
    public PageReference Next() {
        OffsetSize += QueryLimit;
        queryTasks();
        return null;
    }
    public PageReference Previous() {
        OffsetSize -= QueryLimit;
        queryTasks();
        return null;
    }
   public PageReference save() {
        update tasks;
        return ApexPages.CurrentPage();
     }
 
    }
I've a requirement to do sorting . I did it with sort() but does only in ascending way. My client wants to have column sorting something like arrow sorting ,how can i attempt to do this with my code ? Please help. I'm really in a need to get this done.I'm referring to link : http://www.sundoginteractive.com/sunblog/posts/a-recipe-for-column-sorting-salesforce-visualforce-page which also doesnt work.

Stressed out with this.Thanks in advance,James.


    public class PagingTasksController{

    public List<Task> tasks;
    public Integer CountTotalRecords{get;set;}
    public String QueryString {get;set;}
    public Integer OffsetSize = 0;
    private Integer QueryLimit = 3;
    public List<Task> lstTasks;
    public String searchText {get;set;}
  
    public PagingTasksController (){
        //CountTotalRecords= [select count() from Task];
    }
  


    public List<Task> getTasks(){
        if(tasks == null){
            tasks = new List<Task>();
        }
        return tasks;
    }
  
    public void findTasks(){
        String qStr2 = 'Select count() from Task where Subject like \'%'+searchText+'%\' OR Status like \'%'+searchText+'%\'';
        CountTotalRecords = Database.countQuery(qStr2);
        queryTasks();
    }
  
    public void  queryTasks(){
        String qStr = 'Select OwnerId,Subject,Status,Priority from Task where Subject like \'%'+searchText+'%\' OR Status like \'%'+searchText+'%\' Order By Subject,Status limit ' + QueryLimit + ' offset ' + OffsetSize;
        tasks = Database.query(qStr);
        tasks.sort();

    }

    public Boolean getDisablePrevious(){
        if(OffsetSize>0){
            return false;
        }
        else return true;
    }

    public Boolean getDisableNext() {
        if (OffsetSize + QueryLimit < countTotalRecords){
            return false;
        }
        else return true;
    }

    public PageReference Next() {
        OffsetSize += QueryLimit;
        queryTasks();
        return null;
    }

    public PageReference Previous() {
        OffsetSize -= QueryLimit;
        queryTasks();
        return null;
    }

      public PageReference save() {
        update tasks;
        return ApexPages.CurrentPage();
     }
   
    }



     <apex:page controller="PagingTasksController">
    <apex:form >
        <apex:pageBlock title="Tasks" id="pgBlock">
           <apex:pageBlockButtons >
               <apex:commandButton action="{!save}" id="saveButton" value="Save"/>
               <apex:commandButton onclick="resetInlineEdit()" id="cancelButton" value="Cancel"/>
           </apex:pageBlockButtons>
   
        <apex:inlineEditSupport showOnEdit="saveButton, cancelButton"
                    hideOnEdit="editButton" event="ondblclick"
                    changedStyleClass="myBoldClass" resetFunction="resetInlineEdit"/>
   
         <apex:inputText id="searchBox" value="{!searchText}"/>
        <apex:commandButton value="Search" reRender="pgTable,pgBlock" action="{!findTasks}"/>
          <apex:pageBlockTable value="{!Tasks}" var="tsk" id="pgTable" >
           <apex:column >
            <apex:outputLink value="{!URLFOR($Action.Task.Delete, tsk.id,['retURL'='/apex/Task_Assignment_Features'])}" >Delete</apex:outputLink>
</apex:column>
         
          <apex:column headerValue="Subject">
            <apex:outputField value="{!tsk.Subject}"/>
           </apex:column>
           <apex:column headerValue="Status">
             <apex:outputField value="{!tsk.Status}"/>
         </apex:column>
         <apex:column headerValue="Priority">
            <apex:outputField value="{!tsk.Priority}"/>
        </apex:column>
        <apex:column headerValue="OwnerId">
            <apex:outputField value="{!tsk.OwnerId}"/>
        </apex:column>
     </apex:pageBlockTable>
       <apex:pageBlockButtons >
                <apex:commandButton value="Previous" action="{!Previous}" rerender="pgTable,pgBlock"
                                    status="status" disabled="{!DisablePrevious}" />
                <apex:commandButton value="Next" action="{!Next}" reRender="pgTable,pgBlock"
                                    status="status" disabled="{!DisableNext}" />
                <apex:actionStatus id="status" startText="Please Wait..."/>
            </apex:pageBlockButtons>
        </apex:pageBlock>
    </apex:form>
     <apex:enhancedlist type="Activity" height="800" rowsPerPage="50" customizable="False"/>
</apex:page>
I've created a really simple pagination with search box and created a simple VF page with inline editing on the fields.
Now,depending on what I do between filling in a value in the field and clicking the Save button,it will affect whether the new value is saved or not.

So if I double click on the Last row, amend value, hit enter.The text turns orange and I get the undo icon as expected and Save, it saves the record.But when I edit and click Save for the previous records, the value goes back to its OLD value and is not updated.


Page :

public class PagingTasksController{

    public List<Task> tasks;
    public Integer CountTotalRecords{get;set;}
    public String QueryString {get;set;}
    public Integer OffsetSize = 0;
    private Integer QueryLimit = 3;
    public List<Task> lstTasks;
    public String searchText {get;set;} 
   
    public PagingTasksController (){
        //CountTotalRecords= [select count() from Task];
    }
   


    public List<Task> getTasks(){
        if(tasks == null){
            tasks = new List<Task>();
        }
        return tasks;
    }
   
    public void findTasks(){
        String qStr2 = 'Select count() from Task where Subject like \'%'+searchText+'%\' OR Status like \'%'+searchText+'%\'';
        CountTotalRecords = Database.countQuery(qStr2);
        queryTasks();
    }
   
    public void  queryTasks(){
        String qStr = 'Select OwnerId,Subject,Status,Priority from Task where Subject like \'%'+searchText+'%\' OR Status like \'%'+searchText+'%\' Order By Subject,Status limit ' + QueryLimit + ' offset ' + OffsetSize;
        tasks = Database.query(qStr);
        tasks.sort();

    }

    public Boolean getDisablePrevious(){
        if(OffsetSize>0){
            return false;
        }
        else return true;
    }

    public Boolean getDisableNext() {
        if (OffsetSize + QueryLimit < countTotalRecords){
            return false;
        }
        else return true;
    }

    public PageReference Next() {
        OffsetSize += QueryLimit;
        queryTasks();
        return null;
    }

    public PageReference Previous() {
        OffsetSize -= QueryLimit;
        queryTasks();
        return null;
    }

   public PageReference save() {
        update tasks;
        return ApexPages.CurrentPage();
    }
   
}

<apex:page controller="PagingTasksController">
    <apex:form >
        <apex:pageBlock title="Tasks" id="pgBlock">
           <apex:pageBlockButtons >
               <apex:commandButton action="{!save}" id="saveButton" value="Save"/>
               <apex:commandButton onclick="resetInlineEdit()" id="cancelButton" value="Cancel"/>
           </apex:pageBlockButtons>
    
        <apex:inlineEditSupport showOnEdit="saveButton, cancelButton"
                    hideOnEdit="editButton" event="ondblclick"
                    changedStyleClass="myBoldClass" resetFunction="resetInlineEdit"/>
    
       <apex:inputText id="searchBox" value="{!searchText}"/>
        <apex:commandButton value="Search" reRender="pgTable,pgBlock" action="{!findTasks}"/>
        <apex:pageBlockTable value="{!Tasks}" var="tsk" id="pgTable" >
   <apex:column >
  <apex:outputLink value="{!URLFOR($Action.Task.Delete, tsk.id,['retURL'='/apex/task_test'])}" >Delete</apex:outputLink>
</apex:column>
          
                <apex:column value="{!tsk.Subject}"/>
                <apex:column value="{!tsk.Status}"/>
                <apex:column value="{!tsk.Priority}"/>
                <apex:column value="{!tsk.OwnerId}"/>
            </apex:pageBlockTable>
            <apex:pageBlockButtons >
                <apex:commandButton value="Previous" action="{!Previous}" rerender="pgTable,pgBlock"
                                    status="status" disabled="{!DisablePrevious}" />
                <apex:commandButton value="Next" action="{!Next}" reRender="pgTable,pgBlock"
                                    status="status" disabled="{!DisableNext}" />
                <apex:actionStatus id="status" startText="Please Wait..."/>
            </apex:pageBlockButtons>
        </apex:pageBlock>
    </apex:form>
     <apex:enhancedlist type="Activity" height="800" rowsPerPage="50" customizable="False"/>
</apex:page>

    
Class :


public class PagingTasksController{

    public List<Task> tasks;
    public Integer CountTotalRecords{get;set;}
    public String QueryString {get;set;}
    public Integer OffsetSize = 0;
    private Integer QueryLimit = 3;
    public List<Task> lstTasks;
    public String searchText {get;set;} 
   
    public PagingTasksController (){
        //CountTotalRecords= [select count() from Task];
    }
     public List<Task> getTasks(){
        if(tasks == null){
            tasks = new List<Task>();
        }
        return tasks;
    }
   
    public void findTasks(){
        String qStr2 = 'Select count() from Task where Subject like \'%'+searchText+'%\' OR Status like \'%'+searchText+'%\'';
        CountTotalRecords = Database.countQuery(qStr2);
        queryTasks();
    }
   
    public void  queryTasks(){
        String qStr = 'Select OwnerId,Subject,Status,Priority from Task where Subject like \'%'+searchText+'%\' OR Status like \'%'+searchText+'%\' Order By Subject,Status limit ' + QueryLimit + ' offset ' + OffsetSize;
        tasks = Database.query(qStr);
        tasks.sort();

    }

    public Boolean getDisablePrevious(){
        if(OffsetSize>0){
            return false;
        }
        else return true;
    }

    public Boolean getDisableNext() {
        if (OffsetSize + QueryLimit < countTotalRecords){
            return false;
        }
        else return true;
    }

    public PageReference Next() {
        OffsetSize += QueryLimit;
        queryTasks();
        return null;
    }

    public PageReference Previous() {
        OffsetSize -= QueryLimit;
        queryTasks();
        return null;
    }

   public PageReference save() {
        update tasks;
        return ApexPages.CurrentPage();
    }
   
}

Am I coding my inline edit incorrectly? Can you see anything unusual?
Hi All,

I have a requirement, where pagination and search functionality has to be done.I did it but there are 2 pageblock values as under

<apex:pageblocktable value="{!SearchResults}" /> // for Search functionality and
another value is  {!tasks} // for pagination. I cannot use both the values which will be incorrect way of coding.How can i achieve both the functionalities ?

I have tried a lot but i couldnt find out how to get it. :(  Experts i need your help here to achieve my goal . My code as under . Have given full code for better understanding .


public with sharing class TaskListController{
  
     // Pagination staets
    public PageReference save() {
        return null;
    }
    public PageReference edit() {
        return null;
    }
        private integer counter=0;  //keeps track of the offset
        private integer list_size=3; //sets the page size or number of rows
        public integer total_size; //used to show user the total size of the list
        public string selectedPage{get;set{selectedPage=value;}
    }
     public TaskListController() {
        total_size = [select count() from Task]; //set the total size in the constructor
        selectedPage='0';
    }
    public Task[] getTasks() {
       if (selectedPage != '0') counter = list_size*integer.valueOf(selectedPage)-list_size;
        try {
            //we have to catch query exceptions in case the list is greater than 2000 rows
                Task[] taskList = [select Id,Subject, Status, Description
                                     from Task
                                     order by Id
                                     limit :list_size
                                    offset :counter];                  
                return taskList;
       
        } catch (QueryException e) {                           
                ApexPages.addMessages(e);                  
                return null;
        }       
    }
   
    public Component.Apex.pageBlockButtons getMyCommandButtons() {
       
        //the reRender attribute is a set NOT a string
        Set<string> theSet = new Set<string>();
        theSet.add('myPanel');
        theSet.add('myButtons');
               
        integer totalPages;
        if (math.mod(total_size, list_size) > 0) {
            totalPages = total_size/list_size + 1;
        } else {
            totalPages = (total_size/list_size);
        }
         integer currentPage;       
        if (selectedPage == '0') {
            currentPage = counter/list_size + 1;
        } else {
            currentPage = integer.valueOf(selectedPage);
        }
        Component.Apex.pageBlockButtons pbButtons = new Component.Apex.pageBlockButtons();       
        pbButtons.location = 'top';
        pbButtons.id = 'myPBButtons';
        Component.Apex.outputPanel opPanel = new Component.Apex.outputPanel();
        opPanel.id = 'myButtons';
                               
        //the Previous button will alway be displayed
        Component.Apex.commandButton b1 = new Component.Apex.commandButton();
        b1.expressions.action = '{!Previous}';
        b1.title = 'Previous';
        b1.value = 'Previous';
        b1.expressions.disabled = '{!disablePrevious}';       
        b1.reRender = theSet;
       opPanel.childComponents.add(b1);       
                       
        for (integer i=0;i<totalPages;i++) {
            Component.Apex.commandButton btn = new Component.Apex.commandButton();
           
            if (i+1==1) {
                btn.title = 'First Page';
                btn.value = 'First Page';
                btn.rendered = true;                                       
            } else if (i+1==totalPages) {
                btn.title = 'Last Page';
                btn.value = 'Last Page';
                btn.rendered = true;                           
            } else {
                btn.title = 'Page ' + string.valueOf(i+1) + ' ';
                btn.value = ' ' + string.valueOf(i+1) + ' ';
                btn.rendered = false;            
            }
           if (   (i+1 <= 5 && currentPage < 5)
                || (i+1 >= totalPages-4 && currentPage > totalPages-4)
                || (i+1 >= currentPage-2 && i+1 <= currentPage+2))
            {
                btn.rendered = true;
            }
                                    
            if (i+1==currentPage) {
                btn.disabled = true;
                btn.style = 'color:blue;';
            } 
           btn.onclick = 'queryByPage(\''+string.valueOf(i+1)+'\');return false;';
           opPanel.childComponents.add(btn);
           if (i+1 == 1 || i+1 == totalPages-1) { //put text after page 1 and before last page
                Component.Apex.outputText text = new Component.Apex.outputText();
                text.value = '...';       
                opPanel.childComponents.add(text);
            }
         }
       //the Next button will alway be displayed
        Component.Apex.commandButton b2 = new Component.Apex.commandButton();
        b2.expressions.action = '{!Next}';
        b2.title = 'Next';
        b2.value = 'Next';
        b2.expressions.disabled = '{!disableNext}';       
        b2.reRender = theSet;
        opPanel.childComponents.add(b2);
               
        //add all buttons as children of the outputPanel               
        pbButtons.childComponents.add(opPanel); 
       return pbButtons;

    }   
   
    public PageReference refreshGrid() { //user clicked a page number       
        system.debug('**** ' + selectedPage);
        return null;
    }
    public PageReference Previous() { //user clicked previous button
        selectedPage = '0';
        counter -= list_size;
        return null;
    }
   public PageReference Next() { //user clicked next button
        selectedPage = '0';
        counter += list_size;
        return null;
    }
    public PageReference End() { //user clicked end
        selectedPage = '0';
        counter = total_size - math.mod(total_size, list_size);
        return null;
    }
    public Boolean getDisablePrevious() { //this will disable the previous and beginning buttons
        if (counter>0) return false; else return true;
    }
    public Boolean getDisableNext() { //this will disable the next and end buttons
        if (counter + list_size < total_size) return false; else return true;
    }
    public Integer getTotal_size() {
        return total_size;
    }
    public Integer getPageNumber() {
        return counter/list_size + 1;
    }

    public Integer getTotalPages() {
        if (math.mod(total_size, list_size) > 0) {
            return total_size/list_size + 1;
        } else {
            return (total_size/list_size);
        }
    } // Pagination ends

      // Search functionality starts here
        
       public apexpages.standardController controller{get;set;}
       public Task l;
       public List<Task> searchResults {get; set; }

      public string searchText
      {
       get
       {
         if (searchText==null) searchText = '';
         return searchText;
       }
      set;
       }
     public TaskListController(ApexPages.StandardController controller)
     {
        this.controller = controller;
        this.l = (Task) controller.getRecord();
      }

    public PageReference search()
    {
      if(SearchResults == null)
      {
        SearchResults = new List<Task>();
      }
     else
     {
        SearchResults.Clear();
     }

  String qry ='Select Id, Subject,Status from Task where Subject like \'%'+searchText+'%\' OR Status like \'%'+searchText+'%\' Order By Subject,Status';
  SearchResults = Database.query(qry);
  searchResults.sort();
   //System.debug(SearchResults);
   return null;
    }
   }

  
 <!-- Page -->

 
<apex:page controller="TaskListController">
      <apex:form id="searchForm">
       <apex:PageBlock mode="edit">    
        <apex:actionFunction action="{!refreshGrid}" name="queryByPage" reRender="myPanel,myButtons" >
        <apex:param name="firstParam" assignTo="{!selectedPage}" value="" />
       </apex:actionFunction>
       <apex:dynamicComponent componentValue="{!myCommandButtons}"/>       
       <apex:outputPanel id="myPanel">
       <apex:pageMessages id="theMessages" />
       <apex:pageblockSection id="searchBlockSection">
          <apex:pageBlockSectionItem id="searchBlockSectionItem">
            <apex:outputLabel >Keyword</apex:outputLabel>
    <apex:panelGroup >
    <apex:inputtext id="searchTextBox" value="{!searchText}"> </apex:inputtext>
    <apex:commandButton Id="btnSearch" action="{!Search}" rerender="renderBlock" status="status" title="Search" value="Search">                    </apex:commandButton>
    </apex:panelGroup>
          </apex:pageBlockSectionItem>
    </apex:pageblockSection>
  
    <apex:actionStatus id="status" startText="Searching... please wait..."/>    
    <apex:pageBlocksection id="renderBlock" >
      <apex:pageblocktable value="{!SearchResults}" var="t" rendered="{!NOT(ISNULL(SearchResults))}" align="center">
            <apex:outputLink value="/{!t.Id}">{!t.Subject}</apex:outputLink>
            <apex:column value="{!t.Subject}"/>
            <apex:outputLink value="/{!t.Id}">{!t.Status}</apex:outputLink>
            <apex:column value="{!t.Status}"/>
            <apex:facet name="footer">Showing Page # {!pageNumber} of {!totalPages}</apex:facet>
      </apex:pageblocktable>   
  </apex:pageBlocksection>
   </apex:outputPanel>
   </apex:pageblock>
  </apex:form>
   <apex:enhancedlist type="Activity" height="800" rowsPerPage="50" customizable="False"/>
</apex:page>
Hi,

I need to implement Sorting in my Visualforce Page on column. I've used my Custom Controller Class to Display records in apex : pageBlockTable, but I'm not able to implement sorting there.Please help. 

Thanks in advance
James

<apex:page standardController="Task" extensions="TaskSearchController">
       <apex:form id="searchForm">
      <apex:PageBlock mode="inlineEdit">      
      <apex:pageblockSection id="searchBlockSection">
       <apex:pageBlockSectionItem id="searchBlockSectionItem">
        <apex:outputLabel >Keyword</apex:outputLabel>
            <apex:panelGroup >
                <apex:inputtext id="searchTextBox" value="{!searchText}">  </apex:inputtext>
                <apex:commandButton Id="btnSearch" action="{!Search}" rerender="renderBlock" status="status" title="Search" value="Search"> </apex:commandButton>
            </apex:panelGroup>
        </apex:pageBlockSectionItem>
    </apex:pageblockSection>
    <apex:actionStatus id="status" startText="Searching... please wait..."/>      
    <apex:pageBlocksection id="renderBlock" >
        <apex:pageblocktable value="{!SearchResults}" var="o" rendered="{!NOT(ISNULL(SearchResults))}">
            <apex:outputLink value="/{!o.Id}">{!o.Subject}</apex:outputLink>
            <apex:column value="{!o.Subject}"/>
            <apex:outputLink value="/{!o.Id}">{!o.Status}</apex:outputLink>
            <apex:column value="{!o.Status}"/>
        </apex:pageblocktable>     
     </apex:pageBlocksection>
      </apex:pageblock>
     </apex:form>
     <apex:enhancedlist type="Activity" height="800" rowsPerPage="50" customizable="False"/>
    </apex:page>


   // Apex 

     public class TaskSearchController
    {
        public apexpages.standardController controller{get;set;}
       
        public Task l;
        public List<Task> searchResults {get; set; }
        public string searchText
    {
    get
        {
            if (searchText==null) searchText = '';
            return searchText;
        }
    set;
        }

    public TaskSearchController(ApexPages.StandardController controller)
    {
        this.controller = controller;
        this.l = (Task) controller.getRecord();
    }
    public PageReference search()
    {
        if(SearchResults == null)
        {
            SearchResults = new List<Task>();
        }
        else
        {
            SearchResults.Clear();
        }

   String qry = 'Select Id,Subject,Status,ActivityDate from Task where Subject like \'%'+searchText+'%\' OR Status like \'%'+searchText+'%\' Order By Subject,Status,ActivityDate';
//    System.debug(qry);
    SearchResults = Database.query(qry);
   // System.debug(SearchResults);
    return null;
  }
}


I'm getting an error on the page . Also how do i include tow values in pageblocktable where one value is {!SearchResults} which i've written already and another which i need to include is {!tasks} ? I need to do pagination with this error getting solved . Experts please help . I really need it.

Thanks in advance.
James.


<apex:page controller="TaskSearchController">

     <apex:form id="searchForm">
      <apex:PageBlock mode="edit">    
    
       <apex:actionFunction action="{!refreshGrid}" name="queryByPage" reRender="myPanel,myButtons" >
       <apex:param name="firstParam" assignTo="{!selectedPage}" value="" />
       </apex:actionFunction>
     
       <apex:dynamicComponent componentValue="{!myCommandButtons}"/>       
       <apex:outputPanel id="myPanel">
       <apex:pageMessages id="theMessages" />
             <apex:pageBlockButtons >
                <apex:commandButton action="{!edit}" id="editButton" value="Edit"/>
                <apex:commandButton action="{!save}" id="saveButton" value="Save"/>
                <apex:commandButton onclick="resetInlineEdit()" id="cancelButton" value="Cancel"/>
            </apex:pageBlockButtons>

            <apex:inlineEditSupport showOnEdit="saveButton, cancelButton"
                     hideOnEdit="editButton" event="ondblclick"
                        changedStyleClass="myBoldClass" resetFunction="resetInlineEdit"/>
           
         <apex:pageblockSection id="searchBlockSection">
         <apex:pageBlockSectionItem id="searchBlockSectionItem">
         <apex:outputLabel >Keyword</apex:outputLabel>
                <apex:panelGroup >
                <apex:inputtext id="searchTextBox" value="{!searchText}"> </apex:inputtext>
                <apex:commandButton Id="btnSearch" action="{!Search}" rerender="renderBlock" status="status" title="Search" value="Search">                    </apex:commandButton>
            </apex:panelGroup>
         </apex:pageBlockSectionItem>
       </apex:pageblockSection>
      <apex:actionStatus id="status" startText="Searching... please wait..."/>    
     <apex:pageBlocksection id="renderBlock" >
    <apex:pageblocktable value="{!SearchResults}" var="t" rendered="{!NOT(ISNULL(SearchResults))}" align="center">

            <apex:outputLink value="/{!t.Id}">{!t.Subject}</apex:outputLink>
            <apex:column value="{!t.Subject}"/>
            <apex:outputLink value="/{!t.Id}">{!t.Status}</apex:outputLink>
            <apex:column value="{!t.Status}"/>
            <apex:facet name="footer">Showing Page # {!pageNumber} of {!totalPages}        </apex:facet>
           
      </apex:pageblocktable>   
   </apex:pageBlocksection>
   </apex:outputPanel>
   </apex:pageblock>
  </apex:form>
    <apex:enhancedlist type="Activity" height="800" rowsPerPage="50" customizable="False"/>
   </apex:page>


 
    //Apex

    public with sharing class TaskListController
    {
        private integer counter=0;  //keeps track of the offset
        private integer list_size=5; //sets the page size or number of rows
        public integer total_size; //used to show user the total size of the list
       
       
        public string selectedPage{get;set{selectedPage=value;}
    }
   
    public TaskListController() {
        total_size = [select count() from Task]; //set the total size in the constructor
        selectedPage='0';
    }
   
    public Task[] getTasks() {
               
        if (selectedPage != '0') counter = list_size*integer.valueOf(selectedPage)-list_size;
        try {
            //we have to catch query exceptions in case the list is greater than 2000 rows
                Task[] taskList = [select Id,Subject, Status, Description
                                     from Task
                                     order by Id
                                     limit :list_size
                                    offset :counter];                  
                return taskList;
       
        } catch (QueryException e) {                           
                ApexPages.addMessages(e);                  
                return null;
        }       
    }
   
    public Component.Apex.pageBlockButtons getMyCommandButtons() {
       
        //the reRender attribute is a set NOT a string
        Set<string> theSet = new Set<string>();
        theSet.add('myPanel');
        theSet.add('myButtons');
               
        integer totalPages;
        if (math.mod(total_size, list_size) > 0) {
            totalPages = total_size/list_size + 1;
        } else {
            totalPages = (total_size/list_size);
        }
       
        integer currentPage;       
        if (selectedPage == '0') {
            currentPage = counter/list_size + 1;
        } else {
            currentPage = integer.valueOf(selectedPage);
        }
    
        Component.Apex.pageBlockButtons pbButtons = new Component.Apex.pageBlockButtons();       
        pbButtons.location = 'top';
        pbButtons.id = 'myPBButtons';
       
        Component.Apex.outputPanel opPanel = new Component.Apex.outputPanel();
        opPanel.id = 'myButtons';
                               
        //the Previous button will alway be displayed
        Component.Apex.commandButton b1 = new Component.Apex.commandButton();
        b1.expressions.action = '{!Previous}';
        b1.title = 'Previous';
        b1.value = 'Previous';
        b1.expressions.disabled = '{!disablePrevious}';       
        b1.reRender = theSet;

        opPanel.childComponents.add(b1);       
                       
        for (integer i=0;i<totalPages;i++) {
            Component.Apex.commandButton btn = new Component.Apex.commandButton();
           
            if (i+1==1) {
                btn.title = 'First Page';
                btn.value = 'First Page';
                btn.rendered = true;                                       
            } else if (i+1==totalPages) {
                btn.title = 'Last Page';
                btn.value = 'Last Page';
                btn.rendered = true;                           
            } else {
                btn.title = 'Page ' + string.valueOf(i+1) + ' ';
                btn.value = ' ' + string.valueOf(i+1) + ' ';
                btn.rendered = false;            
            }
           
            if (   (i+1 <= 5 && currentPage < 5)
                || (i+1 >= totalPages-4 && currentPage > totalPages-4)
                || (i+1 >= currentPage-2 && i+1 <= currentPage+2))
            {
                btn.rendered = true;
            }
                                    
            if (i+1==currentPage) {
                btn.disabled = true;
                btn.style = 'color:blue;';
            } 
           
            btn.onclick = 'queryByPage(\''+string.valueOf(i+1)+'\');return false;';
                
            opPanel.childComponents.add(btn);
           
            if (i+1 == 1 || i+1 == totalPages-1) { //put text after page 1 and before last page
                Component.Apex.outputText text = new Component.Apex.outputText();
                text.value = '...';       
                opPanel.childComponents.add(text);
            }
            
        }
       
        //the Next button will alway be displayed
        Component.Apex.commandButton b2 = new Component.Apex.commandButton();
        b2.expressions.action = '{!Next}';
        b2.title = 'Next';
        b2.value = 'Next';
        b2.expressions.disabled = '{!disableNext}';       
        b2.reRender = theSet;
        opPanel.childComponents.add(b2);
               
        //add all buttons as children of the outputPanel               
        pbButtons.childComponents.add(opPanel); 
 
        return pbButtons;

    }   
   
    public PageReference refreshGrid() { //user clicked a page number       
        system.debug('**** ' + selectedPage);
        return null;
    }
   
    public PageReference Previous() { //user clicked previous button
        selectedPage = '0';
        counter -= list_size;
        return null;
    }

    public PageReference Next() { //user clicked next button
        selectedPage = '0';
        counter += list_size;
        return null;
    }

    public PageReference End() { //user clicked end
        selectedPage = '0';
        counter = total_size - math.mod(total_size, list_size);
        return null;
    }
   
    public Boolean getDisablePrevious() { //this will disable the previous and beginning buttons
        if (counter>0) return false; else return true;
    }

    public Boolean getDisableNext() { //this will disable the next and end buttons
        if (counter + list_size < total_size) return false; else return true;
    }

    public Integer getTotal_size() {
        return total_size;
    }
   
    public Integer getPageNumber() {
        return counter/list_size + 1;
    }

    public Integer getTotalPages() {
        if (math.mod(total_size, list_size) > 0) {
            return total_size/list_size + 1;
        } else {
            return (total_size/list_size);
        }
    }
  
  

      // Search functionality
        
       public apexpages.standardController controller{get;set;}
       public Task l;
       public List<Task> searchResults {get; set; }

      public string searchText
      {
       get
       {
         if (searchText==null) searchText = '';
         return searchText;
       }
      set;
       }

     public TaskListController(ApexPages.StandardController controller)
     {
        this.controller = controller;
        this.l = (Task) controller.getRecord();
      }

    public PageReference search()
    {
      if(SearchResults == null)
      {
        SearchResults = new List<Task>();
      }
     else
     {
        SearchResults.Clear();
     }

       String qry ='Select Id, Subject,Status from Task where Subject like \'%'+searchText+'%\' OR Status like \'%'+searchText+'%\' Order By Subject,Status';
       SearchResults = Database.query(qry);
       //System.debug(SearchResults);
       return null;
       }
    }

Want to do pagination on Task object.So far i've implemented inline edit and search box in it.The doc says StandardsetController does not support Task,hence i'm trying to implement it by using Offset.Referring to http://cloudfollowsdotcom.wordpress.com/2012/12/27/soqloffset/ for pagination .How do implement it ? I'm stucked and really pissed off. Experts please help.



 <apex:page standardController="Task" recordSetVar="tasks" extensions="TaskSearchController">
   <apex:enhancedlist type="Activity" height="800" rowsPerPage="50" customizable="False"/>

   <apex:form id="searchForm">
   <apex:PageBlock mode="inlineEdit">      
   <apex:pageblockSection id="searchBlockSection">
      <apex:pageBlockSectionItem id="searchBlockSectionItem">
      <apex:outputLabel >Keyword</apex:outputLabel>
      <apex:panelGroup >
            <apex:inputtext id="searchTextBox" value="{!searchText}">
            </apex:inputtext>
            <apex:commandButton Id="btnSearch" action="{!Search}" rerender="renderBlock" status="status" title="Search" value="Search">                    </apex:commandButton>
        </apex:panelGroup>
    </apex:pageBlockSectionItem>
</apex:pageblockSection>
<apex:actionStatus id="status" startText="Searching... please wait..."/>      
<apex:pageBlocksection id="renderBlock" >
    <apex:pageblocktable value="{!SearchResults}" var="o" rendered="{!NOT(ISNULL(SearchResults))}">
        <apex:outputLink value="/{!o.Id}">{!o.Subject}</apex:outputLink>
        <apex:column value="{!o.Subject}"/>
    </apex:pageblocktable>     
</apex:pageBlocksection>


// apex

public class TaskSearchController
{
   public apexpages.standardController controller{get;set;}
   public Task l;
   public List<Task> searchResults {get; set; }

  public string searchText
  {
   get
   {
     if (searchText==null) searchText = '';
     return searchText;
   }
  set;
   }

public TaskSearchController(ApexPages.StandardController controller)
{
    this.controller = controller;
    this.l = (Task) controller.getRecord();
  }

public PageReference search()
{
  if(SearchResults == null)
  {
    SearchResults = new List<Task>();
  }
else
{
    SearchResults.Clear();
}

  String qry ='Select Id, Subject,Status from Task where Subject like \'%'+searchText+'%\' OR Status like \'%'+searchText+'%\' OR OwnerId like  \'%'+searchText+'%\' Order By Subject,Status';

  SearchResults = Database.query(qry);
  //System.debug(SearchResults);
  return null;
  }
}
I want to do an inline editing of pageblock for Task object .Scratching my head from hours . Please help me to modify my code .

<!-- VF page -->

<apex:page standardController="Task" extensions="TaskSearchController">
 
     <apex:form id="searchForm">
      <apex:PageBlock mode="edit">     
     
            <apex:pageBlockButtons >
                <apex:commandButton action="{!edit}" id="editButton" value="Edit"/>
                <apex:commandButton action="{!save}" id="saveButton" value="Save"/>
                <apex:commandButton onclick="resetInlineEdit()" id="cancelButton" value="Cancel"/>
            </apex:pageBlockButtons>
       <apex:inlineEditSupport showOnEdit="saveButton, cancelButton"
                     hideOnEdit="editButton" event="ondblclick"
                        changedStyleClass="myBoldClass" resetFunction="resetInlineEdit"/>
            
      <apex:pageblockSection id="searchBlockSection">
       <apex:pageBlockSectionItem id="searchBlockSectionItem">
        <apex:outputLabel >Keyword</apex:outputLabel>
            <apex:panelGroup >
                <apex:inputtext id="searchTextBox" value="{!searchText}">

                </apex:inputtext>
                <apex:commandButton Id="btnSearch" action="{!Search}" rerender="renderBlock" status="status" title="Search" value="Search">                    </apex:commandButton>
            </apex:panelGroup>
        </apex:pageBlockSectionItem>
    </apex:pageblockSection>
    <apex:actionStatus id="status" startText="Searching... please wait..."/>     
    <apex:pageBlocksection id="renderBlock" >
        <apex:pageblocktable value="{!SearchResults}" var="o" rendered="{!NOT(ISNULL(SearchResults))}">
            <apex:outputLink value="/{!o.Id}">{!o.Subject}</apex:outputLink>
            <apex:column value="{!o.Subject}"/>
            <apex:outputLink value="/{!o.Id}">{!o.Status}</apex:outputLink>
            <apex:column value="{!o.Status}"/>
            <apex:outputLink value="/{!o.Id}">{!o.ActivityDate}</apex:outputLink>
            <apex:column value="{!o.ActivityDate}"/>
     </apex:pageblocktable>    
    </apex:pageBlocksection>
   </apex:pageblock>
  </apex:form>

     <apex:enhancedlist type="Activity" height="800" rowsPerPage="50" customizable="False"/>
   </apex:page>


// Apex class


public class TaskSearchController
    {
       public apexpages.standardController controller{get;set;}
       public Task l;
       public List<Task> searchResults {get; set; }

      public string searchText
      {
       get
       {
         if (searchText==null) searchText = '';
         return searchText;
       }
      set;
       }

     public TaskSearchController(ApexPages.StandardController controller)
     {
        this.controller = controller;
        this.l = (Task) controller.getRecord();
      }

    public PageReference search()
    {
      if(SearchResults == null)
      {
        SearchResults = new List<Task>();
      }
     else
     {
        SearchResults.Clear();
     }

String qry ='Select Id,Subject,Status,ActivityDate from Task where Subject like \'%'+searchText+'%\' OR Status like \'%'+searchText+'%\' Order By Subject,Status,ActivityDate';


    SearchResults = Database.query(qry);
   //System.debug(SearchResults);
   return null;
    }
   }

Really appreciate the help.
I'm using SOSL to search Subject,Status and Activitydate on Task object . The search works for only Subject but when i enter status say 'In progress' it is not displaying.

How can i make search run on Subject,Status or by Activitydate as well ? Also,how do i make search work for enhance list created instead of rendering values down ? PLease help .


  <apex:page standardController="Task" extensions="TaskSearchController">
    <apex:enhancedlist type="Activity" height="800" rowsPerPage="50" customizable="False"/>

      <apex:form id="searchForm">
      <apex:PageBlock mode="edit">       
      <apex:pageblockSection id="searchBlockSection">
       <apex:pageBlockSectionItem id="searchBlockSectionItem">
        <apex:outputLabel >Keyword</apex:outputLabel>
            <apex:panelGroup >
                <apex:inputtext id="searchTextBox" value="{!searchText}">

                </apex:inputtext>
                <apex:commandButton Id="btnSearch" action="{!Search}" rerender="renderBlock" status="status" title="Search" value="Search">                    </apex:commandButton>
            </apex:panelGroup>
        </apex:pageBlockSectionItem>
    </apex:pageblockSection>
    <apex:actionStatus id="status" startText="Searching... please wait..."/>       
    <apex:pageBlocksection id="renderBlock" >
        <apex:pageblocktable value="{!SearchResults}" var="o" rendered="{!NOT(ISNULL(SearchResults))}">
            <apex:outputLink value="/{!o.Id}">{!o.Subject}</apex:outputLink>
            <apex:column value="{!o.Subject}"/>

        </apex:pageblocktable>      
    </apex:pageBlocksection>
   </apex:pageblock>
  </apex:form>
   </apex:page>


    // Apex class


     public class TaskSearchController
    {
       public apexpages.standardController controller{get;set;}
       public Task l;
       public List<Task> searchResults {get; set; }

      public string searchText
      {
       get
       {
         if (searchText==null) searchText = '';
         return searchText;
       }
      set;
       }

     public TaskSearchController(ApexPages.StandardController controller)
     {
        this.controller = controller;
        this.l = (Task) controller.getRecord();
      }

    public PageReference search()
    {
      if(SearchResults == null)
      {
        SearchResults = new List<Task>();
      }
     else
     {
        SearchResults.Clear();
     }

     String qry = 'Select Id, Subject,Status from Task where Subject like \'%'+searchText+'%\' Order By Subject,Status';
  // System.debug(qry);
    SearchResults = Database.query(qry);
   // System.debug(SearchResults);
   return null;
    }
   }
Have created a graph which includes bar chart with plotted lines and pie chart in it. I'm trying to fetch values dynamically for bar chart but it is not displaying Kindly help. .I really need help from the community.


      <!-- Vf page-->
      <apex:page controller="HighchartsController">

  
      <script src="https://code.jquery.com/jquery-1.11.1.min.js"></script>
      <script src="https://code.highcharts.com/highcharts.js"></script>
      <script src="https://code.highcharts.com/modules/exporting.js"></script>

     <div id="container" style="min-width: 310px; height: 400px; margin:0 auto"></div>

        <script>
             $(function () {
             $('#container').highcharts({
             title: {
             text: 'Chart showing opportunities'
        },
        xAxis:{
                categories: ['Jan','Feb','Mar','Apr','May']
            },
              labels: {
              items: [{
              html: 'Opportunities',
              style: {
                    left: '50px',
                    top: '18px',
                    color: (Highcharts.theme && Highcharts.theme.textColor) || 'black'
                }
            }]
        },
        series: [ {
            type: 'column',
            name: 'Indian Railways',
            data: "[{!nvs}]"   // values coming from controller and here i need to fetch it.The bar charts is not displaying.
        },
         {
            type: 'spline',
            name: 'Monthly Sales', // Average
            data: [3, 2.67, 3, 6.33, 3.33],     // the value is static and need to fetch dynamically
            marker: {
                lineWidth: 2,
                lineColor: Highcharts.getOptions().colors[3],
                fillColor: 'white'
            }
        },
        {
            type: 'pie',
            name: 'Total consumption',
            data: [ {
                name: 'Lost',
                y:23,
          
                sliced:true,
                selected:true,
                color: Highcharts.getOptions().colors[1] // Opp's Lost color
              },
             {
                name: 'Won',
                 y:19,
            
                color: Highcharts.getOptions().colors[2] // Opp's won color
              }],
               center: [100, 80],
               size: 100,
               showInLegend: false,
               dataLabels:
               {
                 enabled:true
               }
           }]
       });
   });
    </script>
    </apex:page>


       //Apex class
 
   
             
       public class HighchartsController
      {
           // for bar chart
           // N for name , v for data
          public class Nv {
             public String n { get; private set; }      
             public integer v { get; private set; }
                Nv(String n,Integer v) {
                 this.n = n;
                 this.v = v;     
            }
         }
      public Nv[] getnvs() {
        return new Nv[] {
            new Nv('Jan',5),
            new Nv('Feb',45),
            new Nv('Mar',35),
            new Nv('Apr',25) ,    
            new Nv('may',15)
          };
        }
      }

   
Highly appreciate the help.

Want to do pagination on Task object.So far i've implemented inline edit and search box in it.The doc says StandardsetController does not support Task,hence i'm trying to implement it by using Offset.Referring to http://cloudfollowsdotcom.wordpress.com/2012/12/27/soqloffset/ for pagination .How do implement it ? I'm stucked and really pissed off. Experts please help.



 <apex:page standardController="Task" recordSetVar="tasks" extensions="TaskSearchController">
   <apex:enhancedlist type="Activity" height="800" rowsPerPage="50" customizable="False"/>

   <apex:form id="searchForm">
   <apex:PageBlock mode="inlineEdit">      
   <apex:pageblockSection id="searchBlockSection">
      <apex:pageBlockSectionItem id="searchBlockSectionItem">
      <apex:outputLabel >Keyword</apex:outputLabel>
      <apex:panelGroup >
            <apex:inputtext id="searchTextBox" value="{!searchText}">
            </apex:inputtext>
            <apex:commandButton Id="btnSearch" action="{!Search}" rerender="renderBlock" status="status" title="Search" value="Search">                    </apex:commandButton>
        </apex:panelGroup>
    </apex:pageBlockSectionItem>
</apex:pageblockSection>
<apex:actionStatus id="status" startText="Searching... please wait..."/>      
<apex:pageBlocksection id="renderBlock" >
    <apex:pageblocktable value="{!SearchResults}" var="o" rendered="{!NOT(ISNULL(SearchResults))}">
        <apex:outputLink value="/{!o.Id}">{!o.Subject}</apex:outputLink>
        <apex:column value="{!o.Subject}"/>
    </apex:pageblocktable>     
</apex:pageBlocksection>


// apex

public class TaskSearchController
{
   public apexpages.standardController controller{get;set;}
   public Task l;
   public List<Task> searchResults {get; set; }

  public string searchText
  {
   get
   {
     if (searchText==null) searchText = '';
     return searchText;
   }
  set;
   }

public TaskSearchController(ApexPages.StandardController controller)
{
    this.controller = controller;
    this.l = (Task) controller.getRecord();
  }

public PageReference search()
{
  if(SearchResults == null)
  {
    SearchResults = new List<Task>();
  }
else
{
    SearchResults.Clear();
}

  String qry ='Select Id, Subject,Status from Task where Subject like \'%'+searchText+'%\' OR Status like \'%'+searchText+'%\' OR OwnerId like  \'%'+searchText+'%\' Order By Subject,Status';

  SearchResults = Database.query(qry);
  //System.debug(SearchResults);
  return null;
  }
}
I am trying to use a different components in a VF page.At present,the component is made only on Account object.The requirement is to make it for other standard objects like Contacts,Leads etc.

How will this go ?  Thanks in advance. James


       === Page ===
    
<apex:page standardController="Account">  <!-- This is for Account,how to do it for other objects ? -->
      <c:MadoleChartComponent />
     </apex:page>

     ==== Component ===

<apex:component Controller="HighchartsController">
       <script src="https://code.jquery.com/jquery-1.11.1.min.js"></script>
       <script src="https://code.highcharts.com/highcharts.js"></script>
       <script src="https://code.highcharts.com/modules/exporting.js"></script>

      <div id="container" style="min-width: 310px; height: 400px; margin:0 auto"></div>

        <script>
            pieOrdinate = {!X};
           // pieOrdinate = ServerStr.split(',');
             $(function () {
             $('#container').highcharts({
             title: {
             text: 'Chart showing opportunities'
        },
        xAxis:{
                categories: ['Jan','Feb','Mar','Apr','May','Jun','July','Aug','Sept','Oct','Nov','Dec']
            },
              labels: {
              items: [{
              html: 'Opportunities',
              style: {
                    left: '50px',
                    top: '18px',
                    color: (Highcharts.theme && Highcharts.theme.textColor) || 'black'
                }
            }]
        },
        series: [ {
            type: 'column',
            name: 'Indian Railways',
            data: {!str}
            //data:[2,3,4,5,6]
        },
         {
            type: 'spline',
            name: 'Monthly Sales', // Average
           // data: [3, 2.67, 3, 6.33, 3.33],  
           data :{!bar},
            marker: {
                lineWidth: 2,
                lineColor: Highcharts.getOptions().colors[3],
                fillColor: 'white'
            }
        },
        {
            type: 'pie',
            name: 'Total consumption',
            data: [ {
                name: 'Lost',
                //y:23,
                y :parseInt(pieOrdinate[0]),
                sliced:true,
                selected:true,
                color: Highcharts.getOptions().colors[1] // Opp's Lost color
              },
               {
                name: 'Won',
                y:parseInt(pieOrdinate[1]),
                color: Highcharts.getOptions().colors[2] // Opp's won color
              }],
               center: [100, 80],
               size: 100,
               showInLegend: false,
               dataLabels:
               {
                 enabled:true
               }
             }]
         });
      });
      </script>
     </apex:component>


I tried each and every possibility to know where i'm going wrong but still no luck. My issue is my search (i.e. filter) is working on Subject,Status and Date field for Task object .

Now i want to search for one more column which is "OwnerId" . I know it can be done using if condition something like below  but what should be "IF condition " to get to the goal ?

if (logical condition  to filter by owner) {
    qStr + ' and OwnerId in :ownerIds';


I'm really paralyzed and need help.

public class PagingTasksController1{

    public List<Task> Tasks;

   
    public Task del;
    public Task taskDel;
    public Integer CountTotalRecords{get;set;}
    public String QueryString {get;set;}
    public Integer OffsetSize = 0;
    private Integer QueryLimit =3 ;
    public List<Task> lstTasks {get;set;}
    public String searchText {get;set;}
    public String rowIndex {get;set;}
//   public List<Task> attendeeList {get;set;}
    public Date mydate;
    public Integer totalCount {get;set;}
    public string sortField = 'Subject';  // default sort column
    private string sApplySOQL = '';
   public List<Task> delattendeeList {get;set;}

    public List<Task> delAttendees {get; set;}

    public PagingTasksController1(ApexPages.StandardController controller) {

     taskDel= (Task)controller.getRecord();
     Tasks = [Select id,Subject,Status,ActivityDate from Task where OwnerId =: taskDel.Id];
    // this.Tasks=Tasks[0];
     totalCount = Tasks.size();

     delattendeeList = new List<Task>();
     delattendees = new List<Task>();
}


// the current sort direction. defaults to ascending
    public String sortDir {
        get  { if (sortDir == null) {  sortDir = 'asc'; } return sortDir;  }
        set;
    }

    // the current field to sort by. defaults to role name
    public String getsortField() {
        return sortField;
    }

    // the current field to sort by.
    public void setsortField(string value) {
        sortField = value;
    }
            
    // toggles the sorting of query from asc<-->desc
    public void toggleSort() {
        // simply toggle the direction
        sortDir = sortDir.equals('asc') ? 'desc' : 'asc';
      
        integer iIndex = sApplySOQL.indexOf('Order By');
        if (iIndex > -1){
          sApplySOQL = sApplySOQL.substringBefore('Order By');
          sApplySOQL = sApplySOQL + ' Order By ' + sortField + ' ' + sortDir +  ' limit ' + QueryLimit + ' offset ' + OffsetSize;
        }
        tasks = Database.query(sApplySOQL );
    }
  
    public PagingTasksController1 (){
        //CountTotalRecords= [select count() from Task];
        //String qStr2= '7/23/2014';
          
    }

   public List<Task> getTasks(){
        if(tasks == null){
            tasks = new List<Task>();
        }
        return tasks;
    }

    public void findTasks(){
        String qStr2 = 'Select count() from Task where Subject like \'%'+searchText+'%\' OR Status like \'%'+searchText+'%\'';
        CountTotalRecords = Database.countQuery(qStr2);
        queryTasks();
    }

    public void  queryTasks(){
        
        String qStr2= searchText;
        String strnormal = '';
        try{
             mydate = date.parse(qStr2);
        }catch(Exception e)
        { }
           
        String strDate = '';
        if(mydate != null) {
         // strnormal = String.valueOf(mydate );
          String[] qstr3 = String.valueOf(mydate).split(' ',2); 
          strDate = ' ActivityDate =  '+ qstr3[0] + ' ';
        }else{
       
           strDate  =  'Subject like \'%'+searchText +'%\' OR Status like \'%' +searchText+ '%\' Order By '  + sortField;
        }
        String qStr = 'Select OwnerId,Subject,Status,ActivityDate from Task where '  + strDate   ;

         System.debug(qStr );
           
//        String qStr = 'Select OwnerId,Subject,Status,Priority from Task where Subject like \'%'+searchText+'%\' OR Status like \'%'+searchText+ '%\' Order By ' + sortField;

       
       
        sApplySOQL = qStr;
      
        tasks = Database.query(sApplySOQL );
        //tasks.sort();

    }

    public Boolean getDisablePrevious(){
        if(OffsetSize>0){
            return false;
        }
        else return true;
    }

    public Boolean getDisableNext() {
        if (OffsetSize + QueryLimit < countTotalRecords){
            return false;
        }
        else return true;
    }

    public PageReference Next() {
        OffsetSize += QueryLimit;
        queryTasks();
        return null;
    }

    public PageReference Previous() {
        OffsetSize -= QueryLimit;
        queryTasks();
        return null;
    }

      public PageReference save() {
        update tasks;
        return ApexPages.CurrentPage();
     }
    
    public void deleteRow(){

         rowIndex = String.valueOf(ApexPages.currentPage().getParameters().get('rowIndex'));
         System.debug('rowIndex ------------'+rowIndex );
         if(rowIndex!=null)
         {
         Task check=[Select id from Task where id=: rowIndex];
         System.debug('row to be deleted ' + check);
         delete check;
         Tasks=[Select Subject,Status,ActivityDate,OwnerId from Task ];
         update Tasks;
         }
     }
     
  }
Experts please help.

The problem that i'm facing is my my pagination is not working . The QueryLimit does not mark fare ,the table simply searches the word and displays.

Also for "Deleting" records , it is giving me :  List index out of bounds: 4 Error is in expression '{!deleteRow}' in component <apex:commandButton> in page new_test_task_assignment: Class.PagingTasksController1.deleteRow: line 152,.

I'm just messed and struggling.Please help .Thanks in advance .James


public class PagingTasksController1{

    public List<Task> Tasks;
    public Task del;
    public Task taskDel;
    public Integer CountTotalRecords{get;set;}
    public String QueryString {get;set;}
    public Integer OffsetSize = 0;
    private Integer QueryLimit =3 ;
    public List<Task> lstTasks {get;set;}
    public String searchText {get;set;}
    public Integer rowIndex {get;set;}
    public Date mydate;
    public Integer totalCount {get;set;}
    public string sortField = 'Subject';  // default sort column
    private string sApplySOQL = '';
    public List<Task> delattendeeList {get;set;}

    public List<Task> delAttendees {get; set;}
    public PagingTasksController1(ApexPages.StandardController controller) {

     taskDel= (Task)controller.getRecord();
     Tasks = [Select id,Subject,Status,ActivityDate from Task where OwnerId =: taskDel.Id];
    // this.Tasks=Tasks[0];
     totalCount = Tasks.size();

     delattendeeList = new List<Task>();
     delattendees = new List<Task>();
}


// the current sort direction. defaults to ascending
    public String sortDir {
        get  { if (sortDir == null) {  sortDir = 'asc'; } return sortDir;  }
        set;
    }

    // the current field to sort by. defaults to role name
    public String getsortField() {
        return sortField;
    }

    // the current field to sort by.
    public void setsortField(string value) {
        sortField = value;
    }
            
    // toggles the sorting of query from asc<-->desc
    public void toggleSort() {
        // simply toggle the direction
        sortDir = sortDir.equals('asc') ? 'desc' : 'asc';
      
        integer iIndex = sApplySOQL.indexOf('Order By');
        if (iIndex > -1){
          sApplySOQL = sApplySOQL.substringBefore('Order By');
          sApplySOQL = sApplySOQL + ' Order By ' + sortField + ' ' + sortDir +  ' limit ' + QueryLimit + ' offset ' + OffsetSize;
        }
        tasks = Database.query(sApplySOQL );
    }
 
    public PagingTasksController1 (){
        //CountTotalRecords= [select count() from Task];
        //String qStr2= '7/23/2014';
          
    }
   public List<Task> getTasks(){
        if(tasks == null){
            tasks = new List<Task>();
        }
        return tasks;
    }
   public void findTasks(){
        String qStr2 = 'Select count() from Task where Subject like \'%'+searchText+'%\' OR Status like \'%'+searchText+'%\'';
        CountTotalRecords = Database.countQuery(qStr2);
        queryTasks();
    }
   public void  queryTasks(){
        
        String qStr2= searchText;
        String strnormal = '';
        try{
             mydate = date.parse(qStr2);
        }catch(Exception e)
        { }
           
        String strDate = '';
        if(mydate != null) {
         // strnormal = String.valueOf(mydate );
          String[] qstr3 = String.valueOf(mydate).split(' ',2); 
          strDate = ' ActivityDate =  '+ qstr3[0] + ' ';
        }else{
              strDate  =  'Subject like \'%'+searchText +'%\' OR Status like \'%' +searchText+ '%\' Order By '  + sortField;
        }
        String qStr = 'Select OwnerId,Subject,Status,ActivityDate from Task where '  + strDate   ;
        System.debug(qStr );
        sApplySOQL = qStr;
        tasks = Database.query(sApplySOQL );
        //tasks.sort();

    }
  public Boolean getDisablePrevious(){
        if(OffsetSize>0){
            return false;
        }
        else return true;
    }
  public Boolean getDisableNext() {
        if (OffsetSize + QueryLimit < countTotalRecords){
            return false;
        }
        else return true;
    }
  public PageReference Next() {
        OffsetSize += QueryLimit;
        queryTasks();
        return null;
    }
  public PageReference Previous() {
        OffsetSize -= QueryLimit;
        queryTasks();
        return null;
    }
  public PageReference save() {
        update tasks;
        return ApexPages.CurrentPage();
     }
    
  public void deleteRow(){

         rowIndex = Integer.valueOf(ApexPages.currentPage().getParameters().get('rowIndex'));
         System.debug('row to be deleted ' + rowIndex );
         System.debug('row item to be deleted '+ Tasks[rowIndex]);
         del = Tasks.remove(rowIndex);
         delattendeeList.add(del);
     }
     
  }
My arrow sorting is not working. Pressing my head from hours.Any issue with my query ? It is Urgent.

public class PagingTasksController1{

    public List<Task> tasks;
    public Integer CountTotalRecords{get;set;}
    public String QueryString {get;set;}
    public Integer OffsetSize = 0;
    private Integer QueryLimit = 10;
    public List<Task> lstTasks;
    public String searchText {get;set;}
 
    public Date mydate;
    public string sortField = 'Subject';  // default sort column
    private string sApplySOQL = '';

// the current sort direction. defaults to ascending
    public String sortDir {
        get  { if (sortDir == null) {  sortDir = 'asc'; } return sortDir;  }
        set;
    }

    // the current field to sort by. defaults to role name
    public String getsortField() {
        return sortField;
    }

    // the current field to sort by.
    public void setsortField(string value) {
        sortField = value;
    }
           
    // toggles the sorting of query from asc<-->desc
    public void toggleSort() {
        // simply toggle the direction
        sortDir = sortDir.equals('asc') ? 'desc' : 'asc';
     
        integer iIndex = sApplySOQL.indexOf('Order By');
        if (iIndex > -1){
          sApplySOQL = sApplySOQL.substringBefore('Order By');
          sApplySOQL = sApplySOQL + ' Order By ' + sortField + ' ' + sortDir +  ' limit ' + QueryLimit + ' offset ' + OffsetSize;
        }
        tasks = Database.query(sApplySOQL );
    }

    public PagingTasksController1 (){
        //CountTotalRecords= [select count() from Task];
         //String qStr2= '7/23/2014';
   
    }
    public List<Task> getTasks(){
        if(tasks == null){
            tasks = new List<Task>();
        }
        return tasks;
    }

    public void findTasks(){
        String qStr2 = 'Select count() from Task where Subject like \'%'+searchText+'%\' OR Status like \'%'+searchText+'%\'';
        CountTotalRecords = Database.countQuery(qStr2);
        queryTasks();
    }

    public void  queryTasks(){
       
        String qStr2= searchText;
        String strnormal = '';
        try{
             mydate = date.parse(qStr2);
        }catch(Exception e)
        { }
          
        String strDate = '';
        if(mydate != null) {
         // strnormal = String.valueOf(mydate );
          String[] qstr3 = String.valueOf(mydate).split(' ',2);
          strDate = ' ActivityDate =  '+ qstr3[0] + ' ';
        }else{
      
           strDate  =  'Subject like \'%'+searchText +'%\' OR Status like \'%' +searchText+ '%\'';
        }
        String qStr = 'Select OwnerId,Subject,Status, ActivityDate from Task where '  + strDate   ;

         System.debug(qStr );
          
      
        sApplySOQL = qStr;
     
        tasks = Database.query(sApplySOQL );
        //tasks.sort();

    }

    public Boolean getDisablePrevious(){
        if(OffsetSize>0){
            return false;
        }
        else return true;
    }

    public Boolean getDisableNext() {
        if (OffsetSize + QueryLimit < countTotalRecords){
            return false;
        }
        else return true;
    }

    public PageReference Next() {
        OffsetSize += QueryLimit;
        queryTasks();
        return null;
    }

    public PageReference Previous() {
        OffsetSize -= QueryLimit;
        queryTasks();
        return null;
    }

      public PageReference save() {
        update tasks;
        return ApexPages.CurrentPage();
     }
   
  }
I feel like I've wasted enough time tracking it down.Pretty simple thing.

I have a pageBlockTable. One of the links in it, lets me delete that row. After the row is deleted the table should be rerendered so you can see that it has been removed. Currently the record DOES get deleted, but the table is not rerendered. I was wondering if maybe the table is reloading before the record is actually deleteed, causing a 'race' condition type of situation? Anyway, below is the code. Feel free to point out what I am doing wrong.Thanks in advance


<apex:page controller="PagingTasksController1" docType="html-5.0">
    <apex:form >
        <apex:pageBlock title="Tasks" id="pgBlock">
           <apex:pageBlockButtons >
               <apex:commandButton action="{!save}" id="saveButton" value="Save"/>
               <apex:commandButton onclick="resetInlineEdit()" id="cancelButton" value="Cancel"/>
           </apex:pageBlockButtons>
 
        <apex:inlineEditSupport showOnEdit="saveButton, cancelButton"
                    hideOnEdit="editButton" event="ondblclick"
                    changedStyleClass="myBoldClass" resetFunction="resetInlineEdit"/>
 
          <apex:inputText id="searchBox" value="{!searchText}"/>
           <apex:commandButton value="Search" reRender="pgTable,pgBlock" action="{!findTasks}"/>
           <apex:pageBlockTable value="{!Tasks}" var="tsk" id="pgTable" >
          
                 
          <apex:column headerValue="Action" >
             <apex:outputLink value="{!URLFOR($Action.Task.Delete, tsk.id,['retURL'='/apex/New_Test_task_Assignment'])}"> Delete</apex:outputLink>
           </apex:column>

               
          <apex:column headerValue="Subject">
              <apex:facet name="header">
                    <apex:commandLink value="Subject" action="{!toggleSort}" rerender="pgTable" >
                    <apex:param name="sortField" value="Subject" assignTo="{!sortField}"/>
                    <apex:outputPanel rendered="{!BEGINS(sortField,'Subject')}">
                        &nbsp;<apex:image value="{!IF(sortDir = 'asc','/img/arrowDown.gif','/img/arrowUp.gif')}"/>
                    </apex:outputPanel>
                    </apex:commandLink>
                </apex:facet>    
              
                  <apex:outputField value="{!tsk.Subject}"/>
           </apex:column>
                 
           <apex:column headerValue="Status">
               <apex:facet name="header">
                    <apex:commandLink value="Status" action="{!toggleSort}" rerender="pgTable" >
                    <apex:param name="sortField" value="Status" assignTo="{!sortField}"/>
                    <apex:outputPanel rendered="{!BEGINS(sortField,'Status')}">
                        &nbsp;<apex:image value="{!IF(sortDir = 'asc','/img/arrowDown.gif','/img/arrowUp.gif')}"/>
                    </apex:outputPanel>
                    </apex:commandLink>
              </apex:facet>        
 
             <apex:outputField value="{!tsk.Status}"/>
         </apex:column>
                      
     </apex:pageBlockTable>
       <apex:pageBlockButtons >
                <apex:commandButton value="Previous" action="{!Previous}" rerender="pgTable,pgBlock"
                                    status="status" disabled="{!DisablePrevious}" />
                <apex:commandButton value="Next" action="{!Next}" reRender="pgTable,pgBlock"
                                    status="status" disabled="{!DisableNext}" />
                <apex:actionStatus id="status" startText="Please Wait..."/>
            </apex:pageBlockButtons>
        </apex:pageBlock>
    </apex:form>
     <apex:enhancedlist type="Activity" height="800" rowsPerPage="50" customizable="False"/>
</apex:page>
I'm facing a seious issue here for my query :

String qStr = 'Select OwnerId,Subject,Status,Priority from Task where Subject like \'%'+searchText+'%\' OR Status like \'%'+searchText+'%\' Order By Subject,Status limit ' + QueryLimit + ' offset ' + OffsetSize;

Now the issue is , i need to filter this by one more field called "ActivityDate " which is for Task object. The document says , LIKE operator works only on Strings and hence if i'm including OR ActivityDate like \'%'+searchText+'%\'  it will not work.. How can i get this ?  I'm stucked here.Thanks in advance.

public class PagingTasksController1{

    public List<Task> tasks;
    public Integer CountTotalRecords{get;set;}
    public String QueryString {get;set;}
    public Integer OffsetSize = 0;
    private Integer QueryLimit = 5;
    public List<Task> lstTasks;
    public String searchText {get;set;}

    public string sortField = 'Subject';  // default sort column
    private string sApplySOQL = '';

// the current sort direction. defaults to ascending
    public String sortDir {
        get  { if (sortDir == null) {  sortDir = 'asc'; } return sortDir;  }
        set;
    }

    // the current field to sort by. defaults to role name
    public String getsortField() {
        return sortField;
    }

    // the current field to sort by.
    public void setsortField(string value) {
        sortField = value;
    }
            
    // toggles the sorting of query from asc<-->desc
    public void toggleSort() {
        // simply toggle the direction
        sortDir = sortDir.equals('asc') ? 'desc' : 'asc';
      
        integer iIndex = sApplySOQL.indexOf('Order By');
        if (iIndex > -1){
          sApplySOQL = sApplySOQL.substringBefore('Order By');
          sApplySOQL = sApplySOQL + ' Order By ' + sortField + ' ' + sortDir;
        }
        tasks = Database.query(sApplySOQL );
    }
 
    public PagingTasksController1 (){
        //CountTotalRecords= [select count() from Task];
    }
   public List<Task> getTasks(){
        if(tasks == null){
            tasks = new List<Task>();
        }
        return tasks;
    }
    public void findTasks(){
        String qStr2 = 'Select count() from Task where Subject like \'%'+searchText+'%\' OR Status like \'%'+searchText+'%\'';
        CountTotalRecords = Database.countQuery(qStr2);
        queryTasks();
    }
    public void  queryTasks(){
        String qStr = 'Select OwnerId,Subject,Status,Priority from Task where Subject like \'%'+searchText+'%\' OR Status like \'%'+searchText+'%\' Order By Subject,Status limit ' + QueryLimit + ' offset ' + OffsetSize;
        sApplySOQL = qStr;
      
        tasks = Database.query(sApplySOQL );
        //tasks.sort();

    }
    public Boolean getDisablePrevious(){
        if(OffsetSize>0){
            return false;
        }
        else return true;
    }
    public Boolean getDisableNext() {
        if (OffsetSize + QueryLimit < countTotalRecords){
            return false;
        }
        else return true;
    }
    public PageReference Next() {
        OffsetSize += QueryLimit;
        queryTasks();
        return null;
    }
    public PageReference Previous() {
        OffsetSize -= QueryLimit;
        queryTasks();
        return null;
    }
   public PageReference save() {
        update tasks;
        return ApexPages.CurrentPage();
     }
 
    }
I've a requirement to do sorting . I did it with sort() but does only in ascending way. My client wants to have column sorting something like arrow sorting ,how can i attempt to do this with my code ? Please help. I'm really in a need to get this done.I'm referring to link : http://www.sundoginteractive.com/sunblog/posts/a-recipe-for-column-sorting-salesforce-visualforce-page which also doesnt work.

Stressed out with this.Thanks in advance,James.


    public class PagingTasksController{

    public List<Task> tasks;
    public Integer CountTotalRecords{get;set;}
    public String QueryString {get;set;}
    public Integer OffsetSize = 0;
    private Integer QueryLimit = 3;
    public List<Task> lstTasks;
    public String searchText {get;set;}
  
    public PagingTasksController (){
        //CountTotalRecords= [select count() from Task];
    }
  


    public List<Task> getTasks(){
        if(tasks == null){
            tasks = new List<Task>();
        }
        return tasks;
    }
  
    public void findTasks(){
        String qStr2 = 'Select count() from Task where Subject like \'%'+searchText+'%\' OR Status like \'%'+searchText+'%\'';
        CountTotalRecords = Database.countQuery(qStr2);
        queryTasks();
    }
  
    public void  queryTasks(){
        String qStr = 'Select OwnerId,Subject,Status,Priority from Task where Subject like \'%'+searchText+'%\' OR Status like \'%'+searchText+'%\' Order By Subject,Status limit ' + QueryLimit + ' offset ' + OffsetSize;
        tasks = Database.query(qStr);
        tasks.sort();

    }

    public Boolean getDisablePrevious(){
        if(OffsetSize>0){
            return false;
        }
        else return true;
    }

    public Boolean getDisableNext() {
        if (OffsetSize + QueryLimit < countTotalRecords){
            return false;
        }
        else return true;
    }

    public PageReference Next() {
        OffsetSize += QueryLimit;
        queryTasks();
        return null;
    }

    public PageReference Previous() {
        OffsetSize -= QueryLimit;
        queryTasks();
        return null;
    }

      public PageReference save() {
        update tasks;
        return ApexPages.CurrentPage();
     }
   
    }



     <apex:page controller="PagingTasksController">
    <apex:form >
        <apex:pageBlock title="Tasks" id="pgBlock">
           <apex:pageBlockButtons >
               <apex:commandButton action="{!save}" id="saveButton" value="Save"/>
               <apex:commandButton onclick="resetInlineEdit()" id="cancelButton" value="Cancel"/>
           </apex:pageBlockButtons>
   
        <apex:inlineEditSupport showOnEdit="saveButton, cancelButton"
                    hideOnEdit="editButton" event="ondblclick"
                    changedStyleClass="myBoldClass" resetFunction="resetInlineEdit"/>
   
         <apex:inputText id="searchBox" value="{!searchText}"/>
        <apex:commandButton value="Search" reRender="pgTable,pgBlock" action="{!findTasks}"/>
          <apex:pageBlockTable value="{!Tasks}" var="tsk" id="pgTable" >
           <apex:column >
            <apex:outputLink value="{!URLFOR($Action.Task.Delete, tsk.id,['retURL'='/apex/Task_Assignment_Features'])}" >Delete</apex:outputLink>
</apex:column>
         
          <apex:column headerValue="Subject">
            <apex:outputField value="{!tsk.Subject}"/>
           </apex:column>
           <apex:column headerValue="Status">
             <apex:outputField value="{!tsk.Status}"/>
         </apex:column>
         <apex:column headerValue="Priority">
            <apex:outputField value="{!tsk.Priority}"/>
        </apex:column>
        <apex:column headerValue="OwnerId">
            <apex:outputField value="{!tsk.OwnerId}"/>
        </apex:column>
     </apex:pageBlockTable>
       <apex:pageBlockButtons >
                <apex:commandButton value="Previous" action="{!Previous}" rerender="pgTable,pgBlock"
                                    status="status" disabled="{!DisablePrevious}" />
                <apex:commandButton value="Next" action="{!Next}" reRender="pgTable,pgBlock"
                                    status="status" disabled="{!DisableNext}" />
                <apex:actionStatus id="status" startText="Please Wait..."/>
            </apex:pageBlockButtons>
        </apex:pageBlock>
    </apex:form>
     <apex:enhancedlist type="Activity" height="800" rowsPerPage="50" customizable="False"/>
</apex:page>