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
StaciStaci 

Can you use two substringbefore?

I'm trying to copy a case comment from emails and i want it to cut off before text A or before text B.  
CaseComment cc = new CaseComment(CommentBody=myCase.Last_email__c.substringbefore('Text A' OR 'Text B'),parentID=caseId);

What is the correct syntax?  This above obviously does not work
Best Answer chosen by Staci
AbhinavAbhinav (Salesforce Developers) 
myCase.Last_email__c   you are using this string only for commentbody right?

may be you can use if check of particular text is present or not
 
string a ='test@mail.com';

if (a.contains('@'))
{
    String str = a.SubStringBefore('@');
    System.debug('--===>>>'+str);
}

else 
    if (a.contains('.'))
{
String str = a.SubStringBefore('.');

System.debug('--->'+str);
}

 

All Answers

AbhinavAbhinav (Salesforce Developers) 
What if both Text A' and  'Text B' is present?

 
StaciStaci
@Abhinav they won't be, one will come from an email, one comes from a case comment
AbhinavAbhinav (Salesforce Developers) 
myCase.Last_email__c   you are using this string only for commentbody right?

may be you can use if check of particular text is present or not
 
string a ='test@mail.com';

if (a.contains('@'))
{
    String str = a.SubStringBefore('@');
    System.debug('--===>>>'+str);
}

else 
    if (a.contains('.'))
{
String str = a.SubStringBefore('.');

System.debug('--->'+str);
}

 
This was selected as the best answer