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
Linda 98Linda 98 

How to find line break in middle of long text area field.

I am having a long text area field which has long information.
I am trying get one middle line,which is like this.

xxxxxxx
xxxxxxxx
xxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxx




salesforce office:Working hours 
XXXXXXXXXXXXXX
XXXXXXXXXXXXX
XXXXXXXXXXXXXXXX


So i want to get everything after 'salesforce office: '

output in this case= 'working hours' This is dynamic value.

and save that it another text field.I am able to get that everything after office: but its not recognizing line break.


thats were i am struck..I am having other reasons to use apex trigger.So workflow or Builder doesnt work for me.
Any help?Thanks!!


 
Best Answer chosen by Linda 98
Linda 98Linda 98
This actually worked for me.

String cd=Longtextareafield.substring(Longtextareafield.indexof('office:')+8);
 List<String> ln=cd.split('\r\n');
i was using \n and \\n which didnt work .Thank you.    

All Answers

Raj VakatiRaj Vakati
try using 

myInput.split('\n');
Alain CabonAlain Cabon
Hi Linda,

Here is a trick.

1) Create a Custom Label called line_break : "-" (new line) "-"

User-added image


2) Create a first formula field replacing all these $Label.line_break (without "-") with "<BR>"

myField1 = salesforce office:Working hours 
XXXXXXXXXXXXXX
XXXXXXXXXXXXX
XXXXXXXXXXXXXXXX

myFieldFormula1 = SUBSTITUTE( myField1,SUBSTITUTE($Label.line_break, "-", ""),"<BR>")

Result:
myFieldFormula1  = salesforce office:Working hours<BR>XXXXXXXXXXXXXX<BR>XXXXXXXXXXXXX<BR>XXXXXXXXXXXXXXXX

3)  Create a second formula field which uses the first formula field with CONTAINS, FIND, LEFT and SUBSTITUTE(text, old_text, new_text).

myFieldFormula2 = ​SUBSTITUTE(IF(CONTAINS( myFieldFormula1 , '<BR>'), LEFT(myFieldFormula1 , FIND('<BR>', myFieldFormula1 )-1), myFieldFormula1 ),"salesforce office:","")

 
Linda 98Linda 98
I have to get this in Apex trigger as i need to get other(Lookup and other fields)
So i am looking for something which can fix my apex trigger.


thank you!!
Alain CabonAlain Cabon
In Apex, it is very simple with the function split.

String []  lines = myInput.split('\n');
 
Linda 98Linda 98
yes i used that but that is not working for me..
I want to get only this part and save in a string. 
WORKING HOURS   

nothing before and after has to come.How can i get that in apex trigger.




 
Alain CabonAlain Cabon

salesforce office:Working hours 

String []  lines = myInput.split('\n');
String firstLine = lines[0];
String [] before_after_colon = firstLine.split(':');
String before_colon = before_after_colon [0].trim();  // useless here
String after_colon = before_after_colon [1].trim();  // without spaces
System.debug('afer colon:' + after_colon);
System.debug('before colon:' + before_colon);

 
Linda 98Linda 98
This actually worked for me.

String cd=Longtextareafield.substring(Longtextareafield.indexof('office:')+8);
 List<String> ln=cd.split('\r\n');
i was using \n and \\n which didnt work .Thank you.    
This was selected as the best answer