1

I have a lightning component that displays a List of Tasks in a sidebar. I use a SOQL query in the controller to fetch a List that fits the criteria and display them in the component. I manually model the layout of the tasks with html/aura.

It all works fine, but line breaks from the Task.Description are gone. If I test the SOQL query in the console, it also returns the description without the line breaks. What do I do?

3

Your thesis is slightly mistaken. Querying Task.Description in SOQL certainly does return line breaks, but they are suppressed in many contexts where you might look for them.

You can demonstrate this by doing the following in Anonymous Apex, assuming you have Email-type Tasks present:

List<Task> ts = [SELECT Description FROM Task WHERE Subject LIKE 'Email%'];

System.debug(ts[0].Description);

You'll see the email body in your debug logs, complete with line breaks.

However, if you run this query in Query Editor, you'll see in your results that the Description field is collapsed into a single line. And since Description is not an HTML field, if you render it into HTML with {! v.taskRecord.Description } or similar, it'll be treated like the plain text it is - line breaks will be suppressed.

The <lightning:formattedText> component is designed to handle this use case:

It also converts the \r or \n characters into <br /> tags.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.