I have a process that I am looking to create where people can send an email to a specific email address to update the Stage and a custom field called Update. I would like this to be pulled from the body but since I am updating two fields I am not sure exactly how to accomplish this. The email that would be sent would look something like this:
Stage: Closed Won
Update: I am an Update
Whatever is after the colon should be placed in the appropriate field.
Below is what I have so far:
global class OpportunityUpdateEmailHandler implements Messaging.InboundEmailHandler {
global Messaging.InboundEmailResult handleInboundEmail(
Messaging.InboundEmail email, Messaging.InboundEnvelope envelope) {
String subject = email.subject;
Pattern idPattern = Pattern.compile('006[A-Za-z0-9]{12}');
Matcher matcher = idPattern.matcher(subject);
if (!matcher.find()) System.assert(false, 'No Opportunity ID found in the Subject!');
Opportunity opp = [SELECT Name, StageName FROM Opportunity WHERE Id = :matcher.group(0)];
opp.StageName = email.plainTextBody;
update opp;
Messaging.InboundEmailresult result = new Messaging.InboundEmailResult();
result.message = 'You have successfully updated this Opportunities stage to ' + opp.StageName;
return result;
}
}