You need to sign in to do that
Don't have an account?
Hitesh Khatri 13
How to run the inner queries in Salesforce?
How can I run the query in SOQL?
SELECT ID, ParentId FROM (SELECT ID, ParentID, MAX(LastModifiedDate) maxModified FROM Attachment WHERE ParentID IN ('xxxxxxxxxxxx','xxxxxxxxxxx') AND ContentType IN ('image/png', 'image/jpeg', 'image/gif') GROUP BY Id, ParentID ORDER BY MAX(LastModifiedDate) DESC) t GROUP BY t.ParentID
Hi Hemant,
Thanks for Answering to my query and Sorry for not updating about the iabout the problem but I have already resolved the issue. In my case I used
Though your Answer are very helpful.
Thanks You
Regards
Hitesh Khatri
All Answers
First of all, above query syntax is totally wrong. here is the right way for inner query (child queries in salesforce),
Syntax :
select fields,(select fields from sObjectChildRelationshipName) from sObject
Sample Example 1 :
SELECT Id, Name, Industry, AnnualRevenue,
( SELECT Name, Email, BirthDate FROM Contacts )
FROM Account
Sample Example 2 :
SELECT Id, CaseNumber,Status,
(SELECT Id, Name FROM Attachments)
FROM Case
for full reference :
http://www.sfdc99.com/2013/06/24/example-how-to-write-a-cross-object-soql-query-part-2/
i hope it helps you.
Let me inform if it helps you and kindly mark it best answer if it helps you so it make proper solution for others
thanks
sfdcmonkey.com
Hi Piyush,
Thank s for the response. Above queries fetched data from two different table. but what I want is to fetch data with the same table.
In detail:- I want to fetch a list of Attcahment with ID and parentId and I want that the attachment list only contains items with one parentID i.e. only attachment with one parentID which was the last modifield.
For example
List Items;
1. PatrentID A, AttachmentID 1 (LastModified) .
2. ParentId B, AttachmentID 1 (LastModified).
Not like
1. ParentID A, AttachmentID 1.
2. ParentID A, AttachmentID 2.
Can it be possible with a single querry?
Please help.
Thanks
Regards
Hitesh Khatri
I think you should try like below. and you can add more condition in inner query like if you have set of parentId then you Can Use that set in inner query as well. Thanks
Hemant
Hi Hemant,
Thanks for Answering to my query and Sorry for not updating about the iabout the problem but I have already resolved the issue. In my case I used
Though your Answer are very helpful.
Thanks You
Regards
Hitesh Khatri
Please mark your own answer as solved so if any one have same problem then can easily find solution.
Thanks
Hemant