Search code examples
apisalesforcecasesoql

Is there a way to get the case Age using salesforce SOQL?


I'm using the SF Rest API to run some SOQL queries.. running a query on the Case object, trying to get its current Age (= the amount of days passed since the case was opened).

Is there a way to get the actual age of the case? I know SF has its own formula field that can be used in the reports, but can't seem to find the API field name..

Creating a formula is not that good, as it will also count the age of closed cases (meaning continue to count the days after they were closed..)

Any ideas?


Solution

  • Make a conditional formula field. If the case is open, there is no closed date, then calculate from the current time, otherwise get difference between the two dates, Closed and Created.

    (I forget the actual syntax)

    IF (ISNULL(ClosedDate),
    DATEVALUE(NOW() - CreatedDate), 
    DATEVALUE(ClosedDate - CreatedDate))