+ Start a Discussion
Laura BejjaniLaura Bejjani 

Substring

Hi, 

I have a Description field of type Long Text Area. I'm trying to get the first few lines to display. 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. I tried using SOQL but I couldn't. I also tried something like                        
<apex:outputText value="{!LEFT(GoodMorning,4)}"/> and couldn't get it to work. How can I get a substring of the description field to show up in an page. 
Raj VakatiRaj Vakati
Try like this in page .. its working but you might be confused with testing and result is same .. 
 
<apex:page >
    <apex:outputText value="{!LEFT('GoodMorning',4)}"></apex:outputText> <br/>
    <apex:outputText value="{!RIGHT('GoodMorningwelcome',7)}"></apex:outputText>
</apex:page>

 
Laura BejjaniLaura Bejjani
@Raj V - I have tried that and I get the following error 
Failed to save HighlightComponent.cmp: c:HighlightComponent:26,75: No function found for key: LEFT: Source
Laura BejjaniLaura Bejjani
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);
    }
Danish HodaDanish Hoda
Hi All,
You cannot perform these operations on the component itself, use substring() method in JS file and set the data to an attribute.