+ Start a Discussion
ehartyeehartye 

How do I filter lookup field Id's from History and FeedTrackedChange queries?

Is there a good way to filter these out? Here's an example from a Chatter feed component I'm working on: 

 

Here's my controller:

 

 

public with sharing class ChatterObjectFeed {

    public String oID{ get; set; }
    
    public String oType{ get; set; }    
    
    public String feedPost{ get; set; }
    
    public ChatterObjectFeed(){}
    
    public class objFeed{
    	public id createdById {get; set;}
    	public string createdByName {get; set;}
    	public string createdDate {get; set;}
    	public string body {get; set;}
    	public string title {get; set;}
    	public string linkURL {get; set;}
    	public list <FeedTrackedChange> Changes {get; set;}
    	public list <FeedComment> Comments {get; set;}
    	
    	public objFeed()
    	{
    		Changes = new List<FeedTrackedChange>();
    		Comments = new List<FeedComment>();
    	}
    }
    
    

	public list <objFeed> getObjFeed()
	{
		list<objFeed> feed = new list<objFeed>();
		
		string strQuery = 'SELECT Id, Type, CreatedById, CreatedBy.FirstName, CreatedBy.LastName, CreatedDate, ParentId' 
		+ ', FeedPostId, FeedPost.Body, FeedPost.Title, FeedPost.CreatedById, FeedPost.LinkUrl'
		+ ', (SELECT Id, FieldName, OldValue, NewValue FROM FeedTrackedChanges ORDER BY Id DESC)'
	    + ', (SELECT Id, CommentBody, CreatedDate,CreatedById, CreatedBy.FirstName, CreatedBy.LastName FROM FeedComments ORDER BY CreatedDate DESC, ID DESC)'
		+ 'FROM ' + oType + 'Feed WHERE ParentId=\'' + oID + '\' ORDER BY CreatedDate DESC, ID DESC';
		
		for(SObject o : database.query(strQuery))
		{
			objFeed f = new objFeed();
			f.createdById = (string)o.get('CreatedById');
			f.createdByName = (string)o.getSObject('CreatedBy').get('FirstName') + ' ' + (string)o.getSObject('CreatedBy').get('LastName');
			Datetime createdDateDT = (datetime)o.get('CreatedDate');
			f.createdDate = createdDateDT.format();
			
			FeedPost p = (FeedPost)o.getSObject('FeedPost');
			If(p!=Null)
			{
				f.body = p.body;
				f.title = p.Title;
				f.linkURL = p.LinkUrl;
			}
			
			f.Comments = (FeedComment[])o.getSObjects('FeedComments');
			f.Changes = (FeedTrackedChange[])o.getSObjects('FeedTrackedChanges');
			
			feed.add(f);
		}
		
		return feed;
	}
	
}