I want to use ternary operator in apex.i want to check not null for date field

here is my code (list[j-1].EDI_StartDate__c != null) ? list[j-1].EDI_StartDate__c.format() : ''

i am getting a compile time error as First argument of ternary must be Boolean: String.

Please help me to resolve it

1 Answer 1


You just need to write your condition inside open ( and close ) bracket

(list[j-1].EDI_StartDate__c != null ? list[j-1].EDI_StartDate__c.format() : '')

You must log in to answer this question.

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