You need to sign in to do that
Don't have an account?
Thakkar Parth
Issue of not filter by Id on Task object
I'm performing Search for OwnerId on Task object . I have a User (i.e. Owner) named "Nisarg" . Hence when i search for "Nisarg" it does not give me anything.
When i Debug this in Comsole , following is what i get.What it does is , it searches for Subject and Status.But the requirement is also to search for OnwerId as well on Task which is not happening .. Please help to make any modifications .
Thanks in advance,
Marc.
When i Debug this in Comsole , following is what i get.What it does is , it searches for Subject and Status.But the requirement is also to search for OnwerId as well on Task which is not happening .. Please help to make any modifications .
Thanks in advance,
Marc.
USER_DEBUG [131]|DEBUG|Select OwnerId,Subject,Status,ActivityDate from Task where (Subject like '%Nisarg%' OR Status like '%Nisarg%') Order By Subject limit 3 offset 0
private static string JoinSetIds(Set<Id> objIds) { if(objIds == null || objIds.size() == 0) { return ''; } List<string> lIds = new List<string>(); for(Id pId : objIds) { lIds.add((string)pId); } return '(\'' + String.join(lIds, '\',\'' ) + '\')'; } public void queryTasks(){ String qStr2= searchText; Set<Id> ownerIds = new Set<Id>(); String strnormal = ''; try{ mydate = date.parse(qStr2); }catch(Exception e) { } String strDate = ''; String ownerIdsCondition = ''; if(tasks!=null&&tasks.size()>0) { for(Task t : tasks) { if(!ownerIds.contains(t.OwnerId)) ownerIds.add(t.OwnerId); } ownerIdsCondition = ' OwnerId IN '+JoinSetIds(ownerIds) + ' and '; } if(mydate != null) { // strnormal = String.valueOf(mydate ); String[] qstr3 = String.valueOf(mydate).split(' ',2); strDate = ownerIdsCondition+' ActivityDate = '+ qstr3[0] + ' '; }else{ strDate = ownerIdsCondition+'(Subject like \'%'+searchText +'%\' OR Status like \'%' +searchText+ '%\') ' + ' Order By ' + sortField; } String qStr = 'Select OwnerId,Subject,Status,ActivityDate from Task where '+strDate+' limit ' + QueryLimit + ' offset ' + OffsetSize; System.debug(qStr); tasks = Database.query(qStr); }
<apex:column headerValue="OwnerId"> <apex:outputField value="{!tsk.OwnerId}"/> </apex:column>
Looking through your code these lines
are where the problem is. I would expect that your tasks list is null or empty and as such this conditional is never met allowing the loop to start. How are you retrieveing or declaring this list?
So how can i achieve the goal to search the OwnerId ..Will be grateful if you can please help me with the implementation ..I'm just stucked and not able to move ahead .
1) change the variable declaration from
to Then remove your getTasks method and in your constructor (line 66) add something like:
This will then at least give you a default list of all tasks within the system to start working with. From there you need to filter as per your own requirements as this list may overrun the governor limits if you have a large enough volume of tasks.
If you follow the guidance I gave you above and use your existing code after those tweaks your search method will include the Owner Ids of the tasks you have retrieved as per your original code. As you can see in your debug you are having the Owner Ids included.
If you are wanting to include "Nisargs" user as the Owenr Id then you shoudl remove the code looping through the tasks (lines 113-119) and instead retrieve the User record for the given name and change your filter to use the User Id from that query.