0

I have a Description field of type Long Text Area. I'm trying to get the first few lines to display. 1. I tried creating a formula field

LEFT(Description, 500) 

I get Error: You referenced an unsupported field type called "Long Text Area" using the following field: Description. 2.I tried using SOQL but I couldn't get it to work. 3.I also tried something like

 <apex:outputText value="{!LEFT(GoodMorning,4)}"/> 

I got the following error : Failed to save HighlightComponent.cmp: c:HighlightComponent:26,75: No function found for key: LEFT: Source

How can I get a substring of the description field to show up in a custom lightning component. Here's my code:

Controller

public class HighlightComponentController {
@AuraEnabled        

    public static List<Case> findCase (Id recordId) {
        List<Case> details = [SELECT CaseNumber, OwnerId, Description 
                             FROM Case WHERE Id=:recordId];

        return details;
    }

    String description { get; private set; }

    public String truncatedDescription
    {
        get
        {
            return (description == null) ? null : description.abbreviate(3);
        }
    }

}

Component

<aura:attribute name="truncatedDescription" type="String" />
  <p><lightning:formattedText value="{!v.truncatedDescription}"/></p>

Javascript

{
  doInit : function(component, event, helper) {
    var action = component.get("c.findCase");
    action.setParams({
        recordId: component.get("v.recordId")
    });
    action.setCallback(this, function(data) {
        component.set("v.details", data.getReturnValue());
    });
    $A.enqueueAction(action);

    var action2 = component.get("c.truncatedDescription");

    action2.setCallback(this, function(data) {
        component.set("v.truncatedDescription", data.getReturnValue());
    });
    $A.enqueueAction(action2);
}
  • If you can use SOQL, why not make use of String.substring(startIndex, endIndex)? – TSmith Sep 11 '18 at 17:01
  • I didn't think SOQL had a substring method. Here's what my code looks like public static List<Case> findCase (Id recordId) { List<Case> details = [SELECT CaseNumber, OwnerId, Description FROM Case WHERE Id=:recordId]; return details; – Laura Bejjani Sep 11 '18 at 20:59
  • Please edit your post with any clarifications. Do not drop code in the comments. – Adrian Larson Sep 11 '18 at 21:00
1

You cannot reference Long Text Area fields in formulas of any type. You will have to use Apex.

For example, if you have a controller already, set a truncatedDescription instead of just Description.

public with sharing class MyController
{
    public String description { get; private set; }
    public String truncatedDescription
    {
        get
        {
            return (description == null) ? null : description.abbreviate(2000);
        }
    }
}
  • Thanks for your help here's what I have in the controller so far – Laura Bejjani Sep 11 '18 at 20:55
  • @LauraBejjani So just reference truncatedDescription instead of description where you want the shorter version. – Adrian Larson Sep 11 '18 at 20:59
  • Thanks for your help here's what I have in the controller so far public static List<Case> findCase (Id recordId) { List<Case> details = [SELECT CaseNumber, OwnerId, Description FROM Case WHERE Id=:recordId]; return details; How would I do what you describe and display it. I currently have <lightning:formattedText value="{!item.Description}"/> – Laura Bejjani Sep 11 '18 at 21:03
  • @LauraBejjani Please stop dumping code in the comments. Rather, add it to your question via an edit. – Adrian Larson Sep 11 '18 at 22:45
  • I have updated my question. I'm new to Salesforce Development and I'm not sure how to get this to display in my component. I'm currently getting an empty field. – Laura Bejjani Oct 15 '18 at 10:42

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.