You need to sign in to do that
Don't have an account?
Yao Lin 8
Inbound Email Service: update a field
Hello,
I am working on inbound email service to update a field in Salesforce.
When I receive an email from a specific email address, I need to look for the email content to see if it contains words "FULL OUT". If it does, I need to find the serial number on the email content to match a record Container (API: Container__c) in Salesforce. Then update Status field (picklist; API: Status__c) on that Container record. How to write the Apex code to look for the words? Please see the example email below:
From: xxx@gmail.com
Service FULL OUT was performed for shipments listed below
ABCDEF123: (this is the serial number and a container name in Salesforce) I need to find this serial number in email and see if a container record is created in Salesforce.
Size: 12
Destination: NY
Delivery Date: 01/18/2018
I am working on inbound email service to update a field in Salesforce.
When I receive an email from a specific email address, I need to look for the email content to see if it contains words "FULL OUT". If it does, I need to find the serial number on the email content to match a record Container (API: Container__c) in Salesforce. Then update Status field (picklist; API: Status__c) on that Container record. How to write the Apex code to look for the words? Please see the example email below:
From: xxx@gmail.com
Service FULL OUT was performed for shipments listed below
ABCDEF123: (this is the serial number and a container name in Salesforce) I need to find this serial number in email and see if a container record is created in Salesforce.
Size: 12
Destination: NY
Delivery Date: 01/18/2018
Service FULL OUT was performed for shipments listed below
#ABCDEF123:
Size: 12
(or come up with another way to substring the email body)
You can then write a trigger on insert of an EmailMessage perhaps, here is an example:
(this took ages to write up, and will be FULL of syntax errors, please don't copy and paste it into Salesforce and expect to save it, please use it as a basis for learning the final answer!)
All Answers
Service FULL OUT was performed for shipments listed below
#ABCDEF123:
Size: 12
(or come up with another way to substring the email body)
You can then write a trigger on insert of an EmailMessage perhaps, here is an example:
(this took ages to write up, and will be FULL of syntax errors, please don't copy and paste it into Salesforce and expect to save it, please use it as a basis for learning the final answer!)
Well, you can do a very similar thing in Apex in your inbound email service, of course!
This is my code for inbound email class. Can you tell me where I go wrong?
global class CaseSMEmailHandler implements Messaging.InboundEmailHandler {
global Messaging.InboundEmailResult handleInboundEmail(Messaging.InboundEmail email,
Messaging.InboundEnvelope envelope) {
Messaging.InboundEmailResult result = new Messaging.InboundEmailresult();
String search = 'processed';
Case vCon = [SELECT CW_Case_Status__c FROM Case WHERE Id =: email.subject];
if(email.plainTextBody.contains(search))
{
try{
vCon.CW_Case_Status__c = 'completed';
update vCon ;
result.success = true;
}
catch(DmlException e)
{
result.success=false;
System.debug('The following error has occurred: ' + e.getMessage());
}
}
return result;
}
}
I need to pull this number from the email body and update a case field. Any ideas where to start?