4

I would like to get in one query all notes, attachements, Activity histories, tasks events of one Lead. (I'm limited in terms of API calls)

I tried to concatenated queries in this query (Sorry I just started in Salesforce):

SELECT Id, Name,
  (SELECT Subject, Description FROM Event),
  (SELECT Title, Body FROM Note),
  (SELECT Name, Description FROM Attachment),
  (SELECT Subject, Description FROM Task)
  (SELECT LastModifiedDate, Subject, Description from ActivityHistories)
FROM Contact WHERE Id = 'XXX' 

Any hint will be very helpful !

Thanks !

1
  • Welcome to SFSE, Simo. I recommend reading up on how to do SOQL queries and to look over the schema for Salesforce; that will probably answer many of your questions. Have you tried running this query in the Developer Console or Workbench and building it up? – Mike Chale Nov 12 '13 at 17:39
9

Child relationship names are plural, so your query will work (if that's the data you need) if you just put plurals on all subqueries:

Contact c = [SELECT Id, Name,
  (SELECT Subject, Description FROM Events),
  (SELECT Title, Body FROM Notes),
  (SELECT Name, Description FROM Attachments),
  (SELECT Subject, Description FROM Tasks),
  (SELECT LastModifiedDate, Subject, Description from ActivityHistories)
FROM Contact WHERE Id = 'xxx' ];

Note that the name is plural by convention and you can actually set it to something completely unrelated.

Check here for more details.

2
  • Thank you for your prompt answer. Yes it works when i remove this subquery : (SELECT LastModifiedDate, Subject, Description from ActivityHistories) . any clue how to append it to the content ? – Simo Nov 12 '13 at 17:27
  • It works with that as well, but in your original post, you are missing a comma after the Tasks subquery. – zdropic Nov 12 '13 at 17:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.