Can anyone explain what is Pattern idPattern and Matcher in the flowing class?
I've seen in many classes with different patterns like
Pattern idPattern = Pattern.compile('006[A-Za-z0-9]{12}');
and
Pattern idPattern = Pattern.compile('001[A-Za-z0-9]{16}');
Here I want to know what is 006 and [A-Za-z0-9] and {12} individually and what Matcher class will do at idPattern.matcher(subject);
and matcher.find();
global class AccountUpdateEmailHandler implements
Messaging.InboundEmailHandler {
global Messaging.InboundEmailResult handleInboundEmail(
Messaging.InboundEmail email,
Messaging.InboundEnvelope envelope)
{
String subject = email.subject;
Pattern idPattern = Pattern.compile('001[A-Za-z0-9]{12}');
Matcher matcher = idPattern.matcher(subject);
if (!matcher.find()) System.assert(false, 'No Account Id in subject!');
Account account = [SELECT Name FROM Account WHERE Id = :matcher.group(0)];
account.Name = email.plainTextBody;
update account;
Messaging.InboundEmailresult result = new Messaging.InboundEmailResult();
result.message = 'Account Name is now ' + account.Name;
return result;
}
}