You need to sign in to do that
Don't have an account?

Soql not return contact related tasks in batch apex
i was written soql query in my batch class
select id,Status,Stage,WhoId from Task where Whoid =: ContactId and Status =: 'Completed'
the query not getting tasks for contact
please help me
select id,Status,Stage,WhoId from Task where Whoid =: ContactId and Status =: 'Completed'
the query not getting tasks for contact
please help me
You have two tasks in your org, each related to a different contect (but otherwise, the same?).
When you query in the developer console query editor, you can get one to come back, but not the other?
If you are working in test class/method, which I suspect you may be, you are definitly remembering that you cannot access org data from the test methods by default. Another thing I would also look into is when tasks are marked as completed, they are moved into the "activity history" phase of their lifecycle, which might actually have some affect on what you are trying to do? (not sure on that one).
All Answers
I think you have to remove " : " before you write 'Completed' in soql query.
Same result, after modification i run the query in console for particular contact, it is giving same result No rows.
Query i Used: select Id,Subject,Status from Task where WhoId = 'xxxxxxx'
but this is working for some contacts
If your contact haven't any Task then this query gives us No row.
so please put the id of particular Contact wich have any open Task.
Regards
Virendra
Remember Tasks have a WhoId and a WhatId - used for different purposes, as you can read briefly here,
https://developer.salesforce.com/forums/ForumsMain?id=906F00000008wZlIAI
and in the docs here
https://www.salesforce.com/us/developer/docs/api/Content/sforce_api_objects_task.htm
Contact what i am using for testing is having 2 Tasks, and those having WhoId related to Contact. i am not getting what is going on around the Task.
Is there any permissions needed for Task object to get the records
You have two tasks in your org, each related to a different contect (but otherwise, the same?).
When you query in the developer console query editor, you can get one to come back, but not the other?
If you are working in test class/method, which I suspect you may be, you are definitly remembering that you cannot access org data from the test methods by default. Another thing I would also look into is when tasks are marked as completed, they are moved into the "activity history" phase of their lifecycle, which might actually have some affect on what you are trying to do? (not sure on that one).