Skip to main content
update: reducing to two queries
Source Link
Patlatus
  • 17.8k
  • 13
  • 82
  • 191

==============================================

Update.

This query [select ParentId from CollaborationGroupFeed WHERE ParentId = '0F936000000cWkMCAU']; just returns '0F936000000cWkMCAU' so it is possible to rewrite this using two queries

List<TopicAssignment> ta = [SELECT EntityId FROM TopicAssignment WHERE TopicId = '0TO30000000Xea1GAC'];
System.Debug(ta);
List<Id> fiList = new List<Id>();
for (TopicAssignment t: ta) {
    fiList.add( t.EntityId );
}
 
List<FeedItem> chatFeed = [SELECT  Id, Body, CommentCount, CreatedDate, LikeCount, LinkUrl, ParentId, RelatedRecordId, Title, Type,
                                (SELECT Id, CommentBody, CreatedDate, CreatedById, FeedItemId, ParentId FROM FeedComments)
                            FROM FeedItem 
                            WHERE (Id IN :fiList
                            OR ParentId = '0F936000000cWkMCAU')
                            AND CreatedDate >= 2015-12-15T00:00:00Z];

==============================================

Update.

This query [select ParentId from CollaborationGroupFeed WHERE ParentId = '0F936000000cWkMCAU']; just returns '0F936000000cWkMCAU' so it is possible to rewrite this using two queries

List<TopicAssignment> ta = [SELECT EntityId FROM TopicAssignment WHERE TopicId = '0TO30000000Xea1GAC'];
System.Debug(ta);
List<Id> fiList = new List<Id>();
for (TopicAssignment t: ta) {
    fiList.add( t.EntityId );
}
 
List<FeedItem> chatFeed = [SELECT  Id, Body, CommentCount, CreatedDate, LikeCount, LinkUrl, ParentId, RelatedRecordId, Title, Type,
                                (SELECT Id, CommentBody, CreatedDate, CreatedById, FeedItemId, ParentId FROM FeedComments)
                            FROM FeedItem 
                            WHERE (Id IN :fiList
                            OR ParentId = '0F936000000cWkMCAU')
                            AND CreatedDate >= 2015-12-15T00:00:00Z];
Fixed missing foreach syntax
Source Link
battery.cord
  • 8.9k
  • 8
  • 32
  • 59

Please try this one

List<TopicAssignment> ta = [SELECT EntityId FROM TopicAssignment WHERE TopicId = '0TO30000000Xea1GAC'];
System.Debug(ta);
List<Id> fiList = new List<Id>();
for (TopicAssignment t: ta) {
    fiList.add( t.EntityId );
}
List<CollaborationGroupFeed> cgf = [select ParentId from CollaborationGroupFeed WHERE ParentId = '0F936000000cWkMCAU'];
System.Debug(cgf);
List<Id> piList = new List<Id>();
for (CollaborationGroupFeed c: cgf ) {
    piList.add( c.ParentId );
}
List<FeedItem> chatFeed = [SELECT  Id, Body, CommentCount, CreatedDate, LikeCount, LinkUrl, ParentId, RelatedRecordId, Title, Type,
                                (SELECT Id, CommentBody, CreatedDate, CreatedById, FeedItemId, ParentId FROM FeedComments)
                            FROM FeedItem 
                            WHERE (Id IN :fiList
                            OR ParentId in :piList)
                            AND CreatedDate >= 2015-12-15T00:00:00Z];

You could use list of SObject only if this is the same SObject.

So, if you do

List<FeedItem> feedItems = [SELECT Id FROM FeedItem WHERE Id IN: fiList ];

you could use either

WHERE (Id IN :fiList)

or

WHERE (Id IN :feedItems )

However, since SObject types are different, you can't put

WHERE (Id IN :cgf )

because here either List of Id is expected or List of FeedItem (which Salesforce can automatically transform to List of Id ) but List of TopicAssignment is not. Because there might be ambiguity if there were two different lookups to FeedItem then it won't be clear which one should be taken.

Please try this one

List<TopicAssignment> ta = [SELECT EntityId FROM TopicAssignment WHERE TopicId = '0TO30000000Xea1GAC'];
System.Debug(ta);
List<Id> fiList = new List<Id>();
for (TopicAssignment t: ta) {
    fiList.add( t.EntityId );
}
List<CollaborationGroupFeed> cgf = [select ParentId from CollaborationGroupFeed WHERE ParentId = '0F936000000cWkMCAU'];
System.Debug(cgf);
List<Id> piList = new List<Id>();
for (CollaborationGroupFeed: cgf ) {
    piList.add( c.ParentId );
}
List<FeedItem> chatFeed = [SELECT  Id, Body, CommentCount, CreatedDate, LikeCount, LinkUrl, ParentId, RelatedRecordId, Title, Type,
                                (SELECT Id, CommentBody, CreatedDate, CreatedById, FeedItemId, ParentId FROM FeedComments)
                            FROM FeedItem 
                            WHERE (Id IN :fiList
                            OR ParentId in :piList)
                            AND CreatedDate >= 2015-12-15T00:00:00Z];

You could use list of SObject only if this is the same SObject.

So, if you do

List<FeedItem> feedItems = [SELECT Id FROM FeedItem WHERE Id IN: fiList ];

you could use either

WHERE (Id IN :fiList)

or

WHERE (Id IN :feedItems )

However, since SObject types are different, you can't put

WHERE (Id IN :cgf )

because here either List of Id is expected or List of FeedItem (which Salesforce can automatically transform to List of Id ) but List of TopicAssignment is not. Because there might be ambiguity if there were two different lookups to FeedItem then it won't be clear which one should be taken.

Please try this one

List<TopicAssignment> ta = [SELECT EntityId FROM TopicAssignment WHERE TopicId = '0TO30000000Xea1GAC'];
System.Debug(ta);
List<Id> fiList = new List<Id>();
for (TopicAssignment t: ta) {
    fiList.add( t.EntityId );
}
List<CollaborationGroupFeed> cgf = [select ParentId from CollaborationGroupFeed WHERE ParentId = '0F936000000cWkMCAU'];
System.Debug(cgf);
List<Id> piList = new List<Id>();
for (CollaborationGroupFeed c: cgf ) {
    piList.add( c.ParentId );
}
List<FeedItem> chatFeed = [SELECT  Id, Body, CommentCount, CreatedDate, LikeCount, LinkUrl, ParentId, RelatedRecordId, Title, Type,
                                (SELECT Id, CommentBody, CreatedDate, CreatedById, FeedItemId, ParentId FROM FeedComments)
                            FROM FeedItem 
                            WHERE (Id IN :fiList
                            OR ParentId in :piList)
                            AND CreatedDate >= 2015-12-15T00:00:00Z];

You could use list of SObject only if this is the same SObject.

So, if you do

List<FeedItem> feedItems = [SELECT Id FROM FeedItem WHERE Id IN: fiList ];

you could use either

WHERE (Id IN :fiList)

or

WHERE (Id IN :feedItems )

However, since SObject types are different, you can't put

WHERE (Id IN :cgf )

because here either List of Id is expected or List of FeedItem (which Salesforce can automatically transform to List of Id ) but List of TopicAssignment is not. Because there might be ambiguity if there were two different lookups to FeedItem then it won't be clear which one should be taken.

2nd for loop called TopicAssignment but should have called CollaborationGroupFeed. Updated the loop and changed variable t to c.
Source Link

Please try this one

List<TopicAssignment> ta = [SELECT EntityId FROM TopicAssignment WHERE TopicId = '0TO30000000Xea1GAC'];
System.Debug(ta);
List<Id> fiList = new List<Id>();
for (TopicAssignment t: ta) {
    fiList.add( t.EntityId );
}
List<CollaborationGroupFeed> cgf = [select ParentId from CollaborationGroupFeed WHERE ParentId = '0F936000000cWkMCAU'];
System.Debug(cgf);
List<Id> piList = new List<Id>();
for (TopicAssignment tCollaborationGroupFeed: cgf ) {
    piList.add( tc.ParentId );
}
List<FeedItem> chatFeed = [SELECT  Id, Body, CommentCount, CreatedDate, LikeCount, LinkUrl, ParentId, RelatedRecordId, Title, Type,
                                (SELECT Id, CommentBody, CreatedDate, CreatedById, FeedItemId, ParentId FROM FeedComments)
                            FROM FeedItem 
                            WHERE (Id IN :fiList
                            OR ParentId in :piList)
                            AND CreatedDate >= 2015-12-15T00:00:00Z];

You could use list of SObject only if this is the same SObject.

So, if you do

List<FeedItem> feedItems = [SELECT Id FROM FeedItem WHERE Id IN: fiList ];

you could use either

WHERE (Id IN :fiList)

or

WHERE (Id IN :feedItems )

However, since SObject types are different, you can't put

WHERE (Id IN :cgf )

because here either List of Id is expected or List of FeedItem (which Salesforce can automatically transform to List of Id ) but List of TopicAssignment is not. Because there might be ambiguity if there were two different lookups to FeedItem then it won't be clear which one should be taken.

Please try this one

List<TopicAssignment> ta = [SELECT EntityId FROM TopicAssignment WHERE TopicId = '0TO30000000Xea1GAC'];
System.Debug(ta);
List<Id> fiList = new List<Id>();
for (TopicAssignment t: ta) {
    fiList.add( t.EntityId );
}
List<CollaborationGroupFeed> cgf = [select ParentId from CollaborationGroupFeed WHERE ParentId = '0F936000000cWkMCAU'];
System.Debug(cgf);
List<Id> piList = new List<Id>();
for (TopicAssignment t: cgf ) {
    piList.add( t.ParentId );
}
List<FeedItem> chatFeed = [SELECT  Id, Body, CommentCount, CreatedDate, LikeCount, LinkUrl, ParentId, RelatedRecordId, Title, Type,
                                (SELECT Id, CommentBody, CreatedDate, CreatedById, FeedItemId, ParentId FROM FeedComments)
                            FROM FeedItem 
                            WHERE (Id IN :fiList
                            OR ParentId in :piList)
                            AND CreatedDate >= 2015-12-15T00:00:00Z];

You could use list of SObject only if this is the same SObject.

So, if you do

List<FeedItem> feedItems = [SELECT Id FROM FeedItem WHERE Id IN: fiList ];

you could use either

WHERE (Id IN :fiList)

or

WHERE (Id IN :feedItems )

However, since SObject types are different, you can't put

WHERE (Id IN :cgf )

because here either List of Id is expected or List of FeedItem (which Salesforce can automatically transform to List of Id ) but List of TopicAssignment is not. Because there might be ambiguity if there were two different lookups to FeedItem then it won't be clear which one should be taken.

Please try this one

List<TopicAssignment> ta = [SELECT EntityId FROM TopicAssignment WHERE TopicId = '0TO30000000Xea1GAC'];
System.Debug(ta);
List<Id> fiList = new List<Id>();
for (TopicAssignment t: ta) {
    fiList.add( t.EntityId );
}
List<CollaborationGroupFeed> cgf = [select ParentId from CollaborationGroupFeed WHERE ParentId = '0F936000000cWkMCAU'];
System.Debug(cgf);
List<Id> piList = new List<Id>();
for (CollaborationGroupFeed: cgf ) {
    piList.add( c.ParentId );
}
List<FeedItem> chatFeed = [SELECT  Id, Body, CommentCount, CreatedDate, LikeCount, LinkUrl, ParentId, RelatedRecordId, Title, Type,
                                (SELECT Id, CommentBody, CreatedDate, CreatedById, FeedItemId, ParentId FROM FeedComments)
                            FROM FeedItem 
                            WHERE (Id IN :fiList
                            OR ParentId in :piList)
                            AND CreatedDate >= 2015-12-15T00:00:00Z];

You could use list of SObject only if this is the same SObject.

So, if you do

List<FeedItem> feedItems = [SELECT Id FROM FeedItem WHERE Id IN: fiList ];

you could use either

WHERE (Id IN :fiList)

or

WHERE (Id IN :feedItems )

However, since SObject types are different, you can't put

WHERE (Id IN :cgf )

because here either List of Id is expected or List of FeedItem (which Salesforce can automatically transform to List of Id ) but List of TopicAssignment is not. Because there might be ambiguity if there were two different lookups to FeedItem then it won't be clear which one should be taken.

Source Link
Patlatus
  • 17.8k
  • 13
  • 82
  • 191
Loading