function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
SforcehariSforcehari 

How we can Query all Activities for a Contact ?

Hai friends,

 

   Can you anybody help me to query all Activities in single query for a contact.

 

 

Thanks in advance

 

sforcehari

Best Answer chosen by Admin (Salesforce Developers) 
srikeerthisrikeerthi

Ok

 

You can do that in this way,

 

Contact[] Con=[select id from Contact];

Contact[] Activitycon=[select id,lastname,(select id,subject,whoid from Events where whoid in: ct),(select id from Tasks where whoid in : ct) from Contact];

 

 

 

All Answers

srikeerthisrikeerthi

Hi

 

You can do it in this way..

 

Contact[] Con=[select id,lastnname from Contact];

Task[] Tasklist=[select id,subject,whoid from Task where whoid in: Con];

Event[] Eventlist=[select id,whoid from Event where whoid in: Con];

 

Since you cannot write query on Activity....

SforcehariSforcehari

Thank u Sree,

 

 But i need them in single query. How we can get all events and tasks for a contact ,with in single QUERY?

 

 

 

Thanks in Advance

sforcehari

srikeerthisrikeerthi

Ok

 

You can do that in this way,

 

Contact[] Con=[select id from Contact];

Contact[] Activitycon=[select id,lastname,(select id,subject,whoid from Events where whoid in: ct),(select id from Tasks where whoid in : ct) from Contact];

 

 

 

This was selected as the best answer
SforcehariSforcehari

Thank you,

 

      It's working fine..Thank u so much.

 

 

Regards,

 

Sforcehari

Vaibhav ParkaleVaibhav Parkale

If you want to get activity Histories in a single query use this -

List<Contact> Cons = [select id,(select id from activityHistories) from Contact];