function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Tom SesselmannTom Sesselmann 

How to get relativeCreatedDate from a SOQL query on FeedItem

I'm currently using the ConnectAPI getFeedElementsFromFeed which let's you access attributes such as relativeCreatedDate.

But I want to use SOQL to retreive Feed Items instead, but when I test the query in Workbench, I can't see a field for relativeCreatedDate, only CreatedDate.

Am I missing something?
Best Answer chosen by Tom Sesselmann
RajeevJainRajeevJain
Few are the reasons.
1 - relativeCreatedDate - Name itself says it is relative date, that means it needs some method to format the created date in Relative date, like 17 min ago, etc.
2 - Since it requires calculation, that is not store in database while creating the feed item, rather it formates the date when you call specific connect API method. Which implicitly run query on the created date and then convert it to relativeCreatedDate.

So my suggestion would be, you just calculate it on your own. Thanks.

All Answers

RajeevJainRajeevJain
Few are the reasons.
1 - relativeCreatedDate - Name itself says it is relative date, that means it needs some method to format the created date in Relative date, like 17 min ago, etc.
2 - Since it requires calculation, that is not store in database while creating the feed item, rather it formates the date when you call specific connect API method. Which implicitly run query on the created date and then convert it to relativeCreatedDate.

So my suggestion would be, you just calculate it on your own. Thanks.
This was selected as the best answer
Tom SesselmannTom Sesselmann
Hmm good points! Is there a library or tool I can use to calculate the relativeCreatedDate? Is the connectAPI function that calculates this public?
RajeevJainRajeevJain
Why not. Just export the data, using the tools which you prefer. Then open that data in Excel like software, and apply some formulas to convert createddate to relative created date in new column. 

Other way is just donwload the CSV, then write down java code to parse that CSV and calcualate diff b/n createddate and now and then convert it to as per your logics and then store them in new column.

But don't think any tool would be there to do it except of Excel. Thanks.
RajeevJainRajeevJain
Can you please share your both components code?