Hello, I have the following text:
I have the 'WOT Order' in this string. What I want to achieve is the following: I created 2 text fields:
1. The Task has been already completed
2. User not allowed to complete the task in future date
Now, I want to store in these fields the WOT Order corresponding to each error message.
First Example: In the first row we have WOT Order :0010 following by both error messages; (1)Task has been already completed. (2)If the user is authorized,then he can set completed date as future date.
I want to populate in this case:
1. The Task has been already completed: 0010
2. User not allowed to complete the task in future: 0010.
Second Example: For the next record I have WOT Order :0020 but its only for this error message: If the user is authorized,then he can set completed date as future date.
I want to populate in this case:
1. The Task has been already completed:
2. User not allowed to complete the task in future date: 0020
And so on... How can I accomplish this? Do I need to use regex?
#Apex Trigger #Apex #REGEX #Sales Cloud #Service Cloud #Automation
I've managed to do it ! :)
String recordDescription = formRecord.SVMX_PS_Description__c
String wordToFind = 'WOT Order :';
Pattern word = Pattern.compile(wordToFind);
Matcher match = word.matcher(formDescription);
while (match.find()) {
substring = formDescription.mid(match.start(), 50);
System.debug('substring '+ substring );
if(substring.contains('If the user is')){
String newString = formDescription.mid(match.start()+12, 7);
listOfWOTwithFirstValidation.add(newString);
formRecord.WOT_Order_Future_date_not_allowed__c = String.Join(new List<String>(listOfWOTwithFirstValidation), '');
}
if(substring.contains('The Task has be')){
String newString = formDescription.mid(match.start()+12, 7);
listOfWOTwithSecondValidation.add(newString);
formRecord.WOT_Order_Task_Already_Completed__c = String.Join(new List<String>(listOfWOTwithSecondValidation), '');
}
}