function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Matthew BracewellMatthew Bracewell 

email to case how can i get information from email body

Hi all,

We are currently using the email to case functionality within our business and have a customer at the moment who is sending us multiple cases per day that we simply need to log and report on. The problem is that they auto generate their emails from their system and as such hold all the detail in the email body. These generally are like:

Patient Name:
Address:
Town:
Post Code:

etc

I was wondering if i could use a workflow or trigger to automatically take this data out of the email body and populate some custom fields?

Any help or direction would be greatly appreciated

rajat Maheshwari 6rajat Maheshwari 6

Hi Matthew,

I would like to request to submit proper usecase, so that It could be fast to make the solution.anyways, below is the sample code snippet, which you ideally can utilize for fruitful results - : 
 

// Retrieves content from the email. 

// Splits each line by the terminating newline character 

// and looks for the position of the phone number and city 

String[] emailBody = email.plainTextBody.split('\n', 0); 

String phoneNumber = emailBody[0].substring(6); 

String city = emailBody[1].substring(5);
 

Thanks
Rajat Maheshwari
rajatzmaheshwari@gmail.com

 

Matthew BracewellMatthew Bracewell
Hi Rajat,

Thanks for your answer,

Below are 2 examples of emails that they have sent in - apologies for the length but this gives you an idea:

*** To reply to this email please do so ONLY via this contact link ****


Example 1 - Email In:

Caller: GORDON MITCHELL -
Site: PRIVATE ADDRESS
Tel: 01633 817304




View call (1227586) (requires network and login access)
View progress of this call (requires network access)

Call Resolution Details
23-Apr-2013 09:50 Gemma Wheeler:
CUT OFF POINT FOR NEXT WEEK COLLECTIONS IS THURSDAY5 PM - IF JOB RAISED AFTER THIS TIME, COLLECTIONS WILL NOT BEGIN UNTIL THE 2ND WEEK AFTER.

23-Apr-2013 12:06 Jane Jones:
ght 514

30-Apr-2013 09:29 Gemma Wheeler:
Mr Mitchell called to say that his box was not collected yesterday (Mr Mitchell also thought a collection was due last week?). Mr Mitchell is very concerned about this - it is first collection and he is very anxious as the box is very full. Please could Mr Mitchell be contacted to advise when collection will be (Mr MiItchell has advised that he will not be home until 2pm, so has asked not to be contacted before then)

30-Apr-2013 14:02 Kate Webb:
chasing with cannon

02-May-2013 16:10 Kate Webb:
Driver did not complete run Monday - he called back tues to collect

01-Apr-2014 10:20 Pauline Lawrence:
ANOTHER COLLECTION & BOX NEEDED ADVISED TO BE DONE 07/04/14 KNOCK DOOR

02-Apr-2014 11:58 Kate Webb:
GHT563

10-Mar-2015 15:31 Sue Williams:
ANOTHER COLLECTION & BOX NEEDED ADVISED TO BE DONE MONDAY 16/03/15 RING BELL AND LISTEN IT HAS RUNG

10-Mar-2015 15:31 Sue Williams:
email_20150310-153158 sent

17-Mar-2015 11:05 Joanne Othen:
MISSED - Driver called yesterday and dropped of replacement box but did not knock to collect the full box. Elderly patients, concerned that they didn't know what to do with the box. Advised driver will call MONDAY 23 MARCH 2015 to collect the full box - please make sure driver knocks door and waits until answered to collect box.
Any different to this date please ring Mr Mitchell to advise.

17-Mar-2015 11:06 Joanne Othen:
email_20150317-110640 sent

16-Feb-2016 11:59 Emma Gigg:
Mr Mitchell called for collection. Pick up 1 box. Yes replacement. Will be outside if not please knock and give time to answer. Advised Monday 22.02.16.

16-Feb-2016 12:00 Emma Gigg:
email_20160216-120049 sent

02-Feb-2017 12:07 Sue Williams:
NEEDS ANOTHER COLLECTION AND NEW BOX COLLECTION DAY 15/02/17 WILL BE OUTSIDE ********PLEASE COLLECT FROM TEMP ADDRESS 13 RIDGEWAY PARK ROAD NEWPORT NP20 5AL 01633 672246*********

02-Feb-2017 12:07 Sue Williams:
email_20170202-120743 sent

20-Feb-2017 10:40 Sue Williams:
NEEDS ANOTHER COLLECTION TOP ACCIDENTLY CLOSED BY D/N'S + NEW BOX COLLECTION DAY WEDNESDAY 01/03/17 ********PLEASE COLLECT FROM TEMP ADDRESS 13 RIDGEWAY PARK ROAD NEWPORT NP20 5AL 01633 672246*********

20-Feb-2017 10:40 Sue Williams:
email_20170220-104041 sent

21-Apr-2017 09:08 Linda Guscott:
Sandra, Daughter rang. Pick up 1 sharps box. Yes replacement 2 x 5 litre. Please knock door but if no response will be outside. Wed 3rd May 17. (NB this is from daughters address, 13 Ridgeway Park Road where gentleman is temporarily staying. His home address is 206 Maesglas Crescent NP20 3DB).


Your Call Details
***FOR UPDATES - CHANGE STATUS***
Patient Name: GORDON MITCHELL
Address: 13 RIDGEWAY PARK ROAD
Town: NEWPORT
Post Code: NP20 5AL
Contact Tel No: 01633 672246
What type of Waste is to be collected: SHARPS X 1
Any special instructions: AD HOC
If Sharps Box - Is a Replacement Required: YES 2 x 5 LITRE
Please give details of where waste will be kept for collection: PLEASE KNOCK BUT IF NO RESPONSE WILL BE OUTSIDE
Query if waste is Cytotoxic: NO
Collection Day (as per WS list): WEDNESDAY 3RD MAY 2017




Email sent by: ID:1549 21-Apr-2017 09:08


Example 2 - Email In:


**** To reply to this email please do so ONLY via this contact link ****


Caller: LINDA PRICE -
Site: St Woolos Hospital
Tel: 07854 674 619


REQUIRES A ONE OFF COLLECTION

View call (3422382) (requires network and login access)
View progress of this call (requires network access)

Call Resolution Details
21-Apr-2017 10:00 Sue Williams:
CUT OFF POINT FOR NEXT WEEK COLLECTIONS IS THURSDAY 12PM - IF JOB RAISED AFTER THIS TIME, COLLECTIONS WILL NOT BEGIN UNTIL THE 2ND WEEK AFTER.

**EMAIL TO: aneurinbevan.homesrv@cannonhygiene.com**


Your Call Details
***FOR UPDATES - CHANGE STATUS***

Patient Name: JOHN HUGHES
Address: FREEMANS OAKS COED Y CAERAU LANE KEMEYS INFERIOR NEWPORT NP 18 1JR


Preferred Telephone No: 01633 401 211

What type of Waste is to be collected: BAG + SHARPS
**Sharps Boxes must be 3/4 full if possible**

Any special instructions/access issues: ONE OFF

If Sharps Box - Is a Replacement Required (how many):NO

Exact details of where waste will be kept for collection: WILL BE OUTSIDE

Is the patient self treating? NO
Is waste Cytotoxic or Dialysis: NO

Caseload Holders Name: FRAILTY
Caseload Holders Base: STW

Collection Day (as per WS list): TUESDAY 02/05/17




Email sent by: ID:1547 21-Apr-2017 10:01


Data that is needed:

I have highlighted in bold in both examples the data that is needed to be mapped out to new custom fields. Unfortunately there can always be extra text in the email which can vary the lines that the data we need sits on.

We need this trigger to kick in whenever the Case Origin is equal to 'Email to Support - Aneurin Bevan'

Hope this helps,

Matt
rajat Maheshwari 6rajat Maheshwari 6

Matthew,

For parsing, please follow below links : -

 https://developer.salesforce.com/forums/?id=906F00000008xHwIAI

Thanks
Rajat Maheshwari
rajatzmaheshwari@gmail.com