0

I am somewhat new to formulas. I have a formula field created on the activities object that is supposed to return a date. I am getting a syntax error when I check the syntax checker.

My formula field has the following code:

if ((task.appraisal_vehicle__c != null) && (SomeOtherClass.APPRAISAL_REC_TYPE.equalsIgnoreCase(task.Type)){
return task.CreatedDate().addDays(7).format();
}

Ideally it adds 7 days to the task.CreatedDate() field and returns that when task.appraisal_vehicle__c is not null and task.Type is equal to a constant defined in another class.

I am not sure why and I even dumbed my code down to:

if (appraisal_vehicle_Number__c != null && Type !=null){

}

and still the same. I think this may be due to my confusion with Tasks & Activities. Not sure what I am doing wrong.

2
  • This doesn't seem like a formula field at all. I think your title is a mismatch for your question content. If it is code, please correct the title and include a more complete sample for context. If it is a formula, please include here the actual content of that formula.
    – Adrian Larson
    Commented Jan 20, 2020 at 22:05
  • The code above is the content of the formula. I specified formula in title to give full context of what I am doing in relation to activities and tasks. It is code within a formula. If you think I am off then can you please kindly recommend a revision?
    – kratos
    Commented Jan 20, 2020 at 22:08

1 Answer 1

1

Formula fields do not and cannot use Apex code. Formulas are written in a domain-specific expression language.

Your Apex appears to be translatable into a formula. You'll need, from the formula reference, the IF() and AND() functions, and you'll need to reformat your comparisons and expressions according to the expectations of the formula language.

3
  • Got it. Only thing I am not clear is how to do the comparison to the class constant. (SomeOtherClass.APPRAISAL_REC_TYPE.equalsIgnoreCase(Type))
    – kratos
    Commented Jan 20, 2020 at 22:39
  • 1
    You can't reference Apex constants in formulas. You'll have to compare to a literal or store the constant in something you can access from a formula, like a Custom Setting or Custom Metadata Type.
    – David Reed
    Commented Jan 20, 2020 at 22:40
  • Thanks again !!
    – kratos
    Commented Jan 20, 2020 at 23:03

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .