def get_single_chatter_feed_with_attachment(feedpost_id, feed_type, binding, directory_name, limit=100)
      begin
        expanded_qstring = <<-HERE
        SELECT #{BASE_FRAG}, #{FEEDPOST_WITH_CONTENT_DATA_FRAG},
        (#{FEED_TRACKED_CHANGE_FRAG}), (#{FEED_COMMENT_FRAG} LIMIT #{limit})
        FROM #{feed_type} where FeedPost.Id= \'#{feedpost_id}\' ORDER BY CreatedDate DESC Limit 1
        HERE

        @logger.info('expanded_string: ' + expanded_qstring)
        deep_result = binding.query(:queryString => expanded_qstring)

        ######### queryMore does not work on FeedPost with Content.##########
        # locator = deep_result.queryResponse.result.queryLocator
        # while !locator.nil?
        #  query_again = binding.queryMore(:queryLocator => locator)
        #  locator = query_again.queryMoreResponse.result.queryLocator
        # end
        #####################################################################

        if !deep_result.Fault.nil?
          raise ChatterFeedError.new(@logger, deep_result.Fault.faultstring.to_s)
        end
        if !deep_result.queryResponse.result.records.FeedComments.nil? && deep_result.queryResponse.result.records.FeedComments[:size].to_i > 1
          # There are more than one feed comments. Therefore, search again without content-data.
          # This is done, because having ContentData in the query string, it will only return only the 1st record of the feed comments.
          qstring_without_content_data = <<-HERE
          SELECT #{BASE_FRAG},
          (#{FEED_TRACKED_CHANGE_FRAG}), (#{FEED_COMMENT_FRAG} LIMIT 20)
          FROM #{feed_type} where FeedPost.Id= \'#{feedpost_id}\' ORDER BY CreatedDate DESC Limit 1
          HERE
          result_without_content_data = binding.query(:queryString => qstring_without_content_data)
          list_of_feed_comments = result_without_content_data.queryResponse.result.records.FeedComments
          deep_result.queryResponse.result.records.FeedComments[:records] = list_of_feed_comments[:records]
        end

        filename = deep_result.queryResponse.result.records.FeedPost.ContentFileName
        filesize = deep_result.queryResponse.result.records.FeedPost.ContentSize
        filedata = deep_result.queryResponse.result.records.FeedPost.ContentData
        result_with_attachment = deep_result.queryResponse.result.records

        local_file_name = nil

        if filename.nil?
          # remote filename is nil, do not write the local file
          @logger.info("remote filename is nil, do not write the local file.")
        else
          # Downloaded files are put in the subdirectory matching each session-id in the /public/tmp directory.
          # creates dir, if it does not exists
          file_writer = Salesforce::FileWriter.new
          local_file_name = file_writer.do_write_file(filename, filesize, filedata, directory_name)
          result_with_attachment.FeedPost.store(:Attachment, local_file_name)
        end

        return result_with_attachment
      end
    rescue Exception => exception
      @logger.info "Cannot create the file: " + exception.message
      result_with_attachment.FeedPost[:attachment] = nil
      return result_with_attachment
    end
def get_single_chatter_feed_with_attachment(feedpost_id, feed_type, binding, directory_name, limit=100)
      begin
        expanded_qstring = <<-HERE
        SELECT #{BASE_FRAG}, #{FEEDPOST_WITH_CONTENT_DATA_FRAG},
        (#{FEED_TRACKED_CHANGE_FRAG}), (#{FEED_COMMENT_FRAG} LIMIT #{limit})
        FROM #{feed_type} where FeedPost.Id= \'#{feedpost_id}\' ORDER BY CreatedDate DESC Limit 1
        HERE

        @logger.info('expanded_string: ' + expanded_qstring)
        deep_result = binding.query(:queryString => expanded_qstring)

        ######### queryMore does not work on FeedPost with Content.##########
        # locator = deep_result.queryResponse.result.queryLocator
        # while !locator.nil?
        #  query_again = binding.queryMore(:queryLocator => locator)
        #  locator = query_again.queryMoreResponse.result.queryLocator
        # end
        #####################################################################

        if !deep_result.Fault.nil?
          raise ChatterFeedError.new(@logger, deep_result.Fault.faultstring.to_s)
        end
        if !deep_result.queryResponse.result.records.FeedComments.nil? && deep_result.queryResponse.result.records.FeedComments[:size].to_i > 1
          # There are more than one feed comments. Therefore, search again without content-data.
          # This is done, because having ContentData in the query string, it will only return only the 1st record of the feed comments.
          qstring_without_content_data = <<-HERE
          SELECT #{BASE_FRAG},
          (#{FEED_TRACKED_CHANGE_FRAG}), (#{FEED_COMMENT_FRAG} LIMIT 20)
          FROM #{feed_type} where FeedPost.Id= \'#{feedpost_id}\' ORDER BY CreatedDate DESC Limit 1
          HERE
          result_without_content_data = binding.query(:queryString => qstring_without_content_data)
          list_of_feed_comments = result_without_content_data.queryResponse.result.records.FeedComments
          deep_result.queryResponse.result.records.FeedComments[:records] = list_of_feed_comments[:records]
        end

        filename = deep_result.queryResponse.result.records.FeedPost.ContentFileName
        filesize = deep_result.queryResponse.result.records.FeedPost.ContentSize
        filedata = deep_result.queryResponse.result.records.FeedPost.ContentData
        result_with_attachment = deep_result.queryResponse.result.records

        local_file_name = nil

        if filename.nil?
          # remote filename is nil, do not write the local file
          @logger.info("remote filename is nil, do not write the local file.")
        else
          # Downloaded files are put in the subdirectory matching each session-id in the /public/tmp directory.
          # creates dir, if it does not exists
          file_writer = Salesforce::FileWriter.new
          local_file_name = file_writer.do_write_file(filename, filesize, filedata, directory_name)
          result_with_attachment.FeedPost.store(:Attachment, local_file_name)
        end

        return result_with_attachment
      end
    rescue Exception => exception
      @logger.info "Cannot create the file: " + exception.message
      result_with_attachment.FeedPost[:attachment] = nil
      return result_with_attachment
    end
1. Returns a single feed with attachment.
 2. <b>'feedpost_id</b> is the id corresponding to this feedpost
 3. <b>'feed_type'</b> can be one of the followings
     Account, Asset, Campaign, Case, Lead, Contact, Contract, Opportunity,
     Product2, Solution, User
     **Note**: UserProfileFeed and NewsFeed are not included here, as they
     are special cases.
 4. <b>'binding'</b> can be passed in directly or using the inherited binding from the
     'Salesforce::SfBase' base class.
 5. <b>'directory_name</b> is the directory in 'public/tmp' for saving the attachment
 6. <b>'limit'</b> is the number of feed comments to retrieve at a time