1
votes

I am just getting my feet wet with Salesforce Formula Fields. I am trying to create a formula field.

I have a field called 'Days Since Last Update' which is a number type. I am trying to use this formula:

TODAY() - LastModifiedDate

I get this error:

Error: Incorrect parameter type for operator '-'. Expected Number, Date, received DateTime

'LastModifiedDate' is a standard field in the 'Case' Object. I know it probably some simple fix, but I cannot get my head around it. I understand that the field is expecting a number type and I am probably returning a Date, but according to the examples I am looking at, the syntax should be correct.

1

1 Answers

1
votes

LastModifiedDate is a field of type DateTime. It seems you can't subtract a DateTime from a Date. What you CAN do, however, is call DATEVALUE(expression) to get a Date out of a DateTime. In this case:
TODAY() - DATEVALUE(LastModifiedDate)

The way the error is meant to be interpreted is that the '-' operator as used on the first object (a Date) was expecting the second object to be either a Number or another Date, but the type of the second object was instead a DateTime.

This page gives an explanation of Formula operators and functions, for easy reference: https://help.salesforce.com/apex/HTViewHelpDoc?id=customize_functions.htm