truncating case description in case assignment email

sure its 2022 and we have force lightning powers that emperor palpatine himself could only dream of, but if you want a good case assignment email, you need visualforce.

i rolled up a nice visualforce email template years ago that includes the case commments - sorted by date!

but the template includes case description, and sometimes people initiate a case via a gigantic email, and all of that email thread would come through on the visualforce assignment email

so i just need to truncate the length of the description.

the original
<apex:outputField value="{!relatedTo.Description}"></apex:outputField>

tried inserting a left in there, could not get anything to save
examples
/apex:outputField

apex:outputText would lose the formatting, regardless of how I tried to work with it, like


/apex:outputText

I even tried abbreviating the string in a vf component, but outputText would lose the formatting

But to work with apex:outputField you need a sObject.

So in my custom component, instead of returning a string, I return a case sObject, with a truncated description field, and used apex:outputField

public with sharing class SortedCaseCommentsController {

  public Id     AttributeCaseId    {get; set;}

  public List<CaseComment> getCaseComments() {
    return [
      SELECT CommentBody, CreatedById, CreatedBy.Name, CreatedDate
      FROM CaseComment
      WHERE ParentId =: this.AttributeCaseId
      ORDER BY CreatedDate DESC LIMIT 3
    ];
  }

  public case getCaseDescription(){
      IF(this.AttributeCaseId != NULL){
      list<Case> caseList = new list<Case> ([select description from Case where Id =: this.AttributeCaseId ]);
      caseList[0].description = caseList[0].description.abbreviate(1500);
      return caseList[0];
      }
      ELSE{return null;}
  }

}
 
0
Kudos
 
0
Kudos

Now read this

Custom User Controller Extension - to allow users to edit fields on user record

[update : captains log june 18 2020. #summer20 release. its a lot easier to use a flow that runs in system mode to do most anything that requires a without-sharing apex controller] As custom controllers can run in system mode,... Continue →