function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
vijendharvijendhar 

display top five lines from long text area filed in salesforce

Hi All,
I have a requirement that, i have long text area field  with Recenct case comments displaying in case object by using some workflow ,
now my requrement is i  have a email template, in that template i need to create top five lines of  comments how can i achive these funcionallity

Thanks

 
pconpcon
If you do this in a Visualforce Email and have a custom controller you can split on the new line character and then get those first five lines.
 
List<String> commentLines = new List<String>();

Integer i = 0;

for (String line : = comment.Body.split('\n')) {
    commentLines.add(line);

    i += 1;
    if (i == 5) {
        break;
    }
}

String shortenedComment = String.join(commentLines, '\n');
NOTE: This code has not been tested and may contain typographical or logical errors