0

What is the correct way to check if a long text area field is null/empty? Does a simple != null suffice?

if (numberApprove>0 && insuranceRecord.Comments_Private__c != null){
    sMessage = sMessage + 'Include information in the Comments field about approvals';
}
2
  • What's the context?
    – sfdcfox
    Commented Jul 19, 2019 at 18:14
  • This is Apex code that checks whether the comment section in an insurance record has been populated. If the comment section has not been populated then they will receive a dialog box with the message "Include information in the Comments field about approvals".
    – ebar
    Commented Jul 19, 2019 at 18:18

1 Answer 1

4

Long text area value is still a string so you can use standard string functions. Try this:

if (numberApprove>0 && String.isBlank(insuranceRecord.Comments_Private__c)){
    sMessage = sMessage + 'Include information in the Comments field about approvals';
}

If you want to check whether it is not blank, then use String.isNotBlank(insuranceRecord.Comments_Private__c)

1
  • That works lovely, thanks
    – ebar
    Commented Jul 19, 2019 at 18:46

You must log in to answer this question.

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