我下面的顶点代码从案例对象的主题字段中提取电话号码。问题是,我无法与帐户电话字段进行比较,因为电话字段只是数字,就像这样 9998887777。我尝试使用模式的不同解决方案,但到目前为止没有运气,我被困住了。任何帮助表示赞赏。
public class PhoneNumberExtract {
@InvocableMethod(label = 'Extract Phone Number' description = 'Extract phone number from Subject field in Case object')
public static List<String> extractPhoneNum(List<Case> cases){
List<String> lstString = new List<String>();
for (Case recCase : cases) {
for (Integer i=0; i < recCase.Subject.length(); i++) {
if (recCase.Subject.subString(i, i+1) == '(') {
lstString.add(recCase.Subject.subString(i,i+14));
break;
}
}
}
String finalString = lstString.get(0);
finalString.replace('[()\s-]', '');
List<String> lstStringFinal = finalString.split(',');
return lstStringFinal;
}
}
我尝试使用模式,但没有成功
String finalString = lstString.get(0);
finalString.replace('[()\s-]', '');
List<String> lstStringFinal = finalString.split(',');
return lstStringFinal;
我正在使用此代码。如果它也适合您,请尝试此代码。
public class ExtractPhoneForNimbus {
@InvocableMethod(label = 'Extract Phone Number' description = 'Extract phone number from Subject field in Case object')
public static List<String> extractPhoneNum(List<Case> cases) {
List<String> phoneNumbers = new List<String>();
Pattern phonePattern = Pattern.compile('\\(?\\d{3}\\)?[-\\s]?\\d{3}[-\\s]?\\d{4}');
for (Case recCase : cases) {
Matcher matcher = phonePattern.matcher(recCase.Subject);
while (matcher.find()) {
// Extract the phone number and remove non-numeric characters
String phoneNumber = matcher.group().replaceAll('[^\\d]', '');
phoneNumbers.add(phoneNumber);
}
}
return phoneNumbers;
}
}