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
Sathish LoganathanSathish Loganathan 

How to remove entire Text after hyphen from a TexBody (EmailMessage field)

Hi,

Help needed in removing the text which is present after hyphen(--) from a TexBody (EmailMessage field). So my request is to copy only the new Email to case comment.

for Example:

Hello,

This is an example.

--- Original Message--

Previous Email Threads


Copy only "Hello,

This is an example."  to the case comment field.

Kindly please let me know a possible solution to acheive this.

Thanks in Advance.

Regards,
Sathish 
Best Answer chosen by Sathish Loganathan
GarryPGarryP
it should be easy.
Just use STRING FUNCTIONS in apex. BElow solution should work (have not tried though)

1. put the message in String variable
2. use IndexOf String function which will give you first occurence of hyphen
3. use SubsTring function

here is the documentation-
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_methods_system_string.htm
 

All Answers

GarryPGarryP
it should be easy.
Just use STRING FUNCTIONS in apex. BElow solution should work (have not tried though)

1. put the message in String variable
2. use IndexOf String function which will give you first occurence of hyphen
3. use SubsTring function

here is the documentation-
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_methods_system_string.htm
 
This was selected as the best answer
Sathish LoganathanSathish Loganathan
Thank you Girish. This worked 
GarryPGarryP
Can you please select the answer as Solved, if worked perfectly! :) This will help other community members as well!