You need to sign in to do that
Don't have an account?
delete button does not work with search by OwnerId
My delete button does not work after putting endless efforts and thought to post here.When i click on Delete button, its just rerendering and not deleting after trying with actionSupport.
Also I'm not able to search by OwnerId though my query is right. Please 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 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; Set<Id> ownerIds = new Set<Id>(); 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; } if (ownerIds != null && ownerIds.size() > 0){ String qStr = 'Select OwnerId,Subject,Status,ActivityDate from Task where '+strDate+' limit ' + QueryLimit + ' offset ' + OffsetSize +' and OwnerId in :ownerIds'; System.debug(qStr); tasks = Database.query(qStr); } //String qStr ='Select OwnerId,Subject,Status,ActivityDate from Task where \''+strDate +'\' limit ' + QueryLimit + ' offset ' + OffsetSize; // String qStr = 'Select OwnerId,Subject,Status,ActivityDate from Task where '+strDate+' limit ' + QueryLimit + ' offset ' + OffsetSize; // String qStr = 'Select OwnerId,Subject,Status,Priority from Task where Subject like \'%'+searchText+'%\' OR Status like \'%'+searchText+ '%\' Order By ' + sortField; //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; } } } <apex:page controller="PagingTasksController1" docType="html-5.0"> <apex:form > <apex:variable var="rowNumber" value="{!0}"/> <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:commandButton value="Delete" action="{!deleteRow}" reRender="pgTable"> <apex:param name="rowIndex" value="{!tsk.id}"/> </apex:commandButton> </apex:column> <!-- <apex:column headerValue="Action" > <apex:outputLink value="{!URLFOR($Action.Task.Delete, .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')}"> <apex:image value="{!IF(sortDir = 'desc','/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')}"> <apex:image value="{!IF(sortDir = 'desc','/img/arrowDown.gif','/img/arrowUp.gif')}"/> </apex:outputPanel> </apex:commandLink> </apex:facet> <apex:outputField value="{!tsk.Status}"/> </apex:column> <apex:column headerValue="OwnerId"> <apex:outputField value="{!tsk.OwnerId}"/> </apex:column> <apex:column headerValue="date"> <apex:outputField value="{!tsk.ActivityDate}"/> </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>
You need to assignTo attribute on param to pass parameter.
Check this http://blog.jeffdouglas.com/2010/03/04/passing-parameters-with-a-commandbutton/
so the end of soql string will look like
just add this method and rewrite like this
Error is in expression '{!findTasks}' in component <apex:commandButton> in page final_task_features: Class.PagingTasksController1.queryTasks: line 135, column 1
Class.PagingTasksController1.findTasks: line 81, column 1
Class.PagingTasksController1.queryTasks: line 135, column 1
Class.PagingTasksController1.findTasks: line 81, column 1
I did something like this.
SELECT whar FROM object WHERE condition ORDER BY field LIMIT count OFFSET count
In your last code you put "and OwnerId in (idsGoesHere)" after OFFSET...
System.QueryException: expecting a colon, found 'Order'
Error is in expression '{!findTasks}' in component <apex:commandButton> in page demo: Class.PagingTasksController2.queryTasks: line 140, column 1
Class.PagingTasksController2.findTasks: line 80, column 1
22:22:55:223 USER_DEBUG [139]|DEBUG| Select OwnerId,Subject,Status,ActivityDate from Task where (Subject like '%Pa%' OR Status like '%Pa%') and OwnerId in Order By Subject limit 3 offset 0
Should be something like
But my search is still not working ..
This sample shoudn't result an error.
Here it is .
Select OwnerId,Subject,Status,ActivityDate from Task where (Subject like '%Nisarg%' OR Status like '%Nisarg%') Order By Subject limit 3 offset 0
But as you said if its NULL, it will be empty. When can this condition happen ?
So logic will not reach your ctor logic(where you assign Tasks for the first time).
Check this artincles:
http://www.salesforce.com/us/developer/docs/pages/Content/pages_controller_custom.htm
http://www.salesforce.com/us/developer/docs/pages/Content/pages_controller_extension.htm
What should be the workaround to get to this ?