+ Start a Discussion
Onur Kaya 9Onur Kaya 9 

Extract Id from long text

Hi,

I have inbound email code, I am collecting emails from Bank Account. I need to fetch the Id from the long text field. I have sample record here. Can anyone please share sample code with me to fetch the Fed Reference #. ?

ABXDEFGHIJKLMN12345
In accordance with your instructions, we have DEBITED your account: **********XXX
for $1.00. If you have any questions, please contact your banker.


Fed Reference #: ABXDEFGHIJKLMN12345


Sender Bank Information:
ABA #: 111111111111
Bank Name: Sample Bank

Thank you in adance.
Best Answer chosen by Onur Kaya 9
Vishwajeet kumarVishwajeet kumar
private static Map<String, String> getEmailFieldNameToValueMap(String emailBody) {
        String delimiter = ':';        
        String[] emailBodyRows = emailBody.split('\n');        
        Map<String, String> emailFieldNameToValueMap = new Map<String, String>();
        
        for (String emailBodyRow : emailBodyRows) {
            System.debug(LoggingLevel.ERROR, ':::::::emailBodyRow = ' + emailBodyRow);           
            Integer delimiterIndex = emailBodyRow.indexOf(delimiter);
            System.debug(LoggingLevel.ERROR, ':::::::delimiterIndex = ' + delimiterIndex);            
            if (delimiterIndex != -1) {
                String emailFieldName = emailBodyRow.substringBefore(delimiter);
                String emailFieldValue = emailBodyRow.substringAfter(delimiter);              
                
                emailFieldName = trim(emailFieldName);
                emailFieldValue = trim(emailFieldValue);                
                
                emailFieldNameToValueMap.put(emailFieldName, emailFieldValue);
            }
        }
        
        return emailFieldNameToValueMap;
    }

Hey, try above. it should give you all rows, with name and value sepearted by ':'. Modify as needed.

All Answers

Vishwajeet kumarVishwajeet kumar
private static Map<String, String> getEmailFieldNameToValueMap(String emailBody) {
        String delimiter = ':';        
        String[] emailBodyRows = emailBody.split('\n');        
        Map<String, String> emailFieldNameToValueMap = new Map<String, String>();
        
        for (String emailBodyRow : emailBodyRows) {
            System.debug(LoggingLevel.ERROR, ':::::::emailBodyRow = ' + emailBodyRow);           
            Integer delimiterIndex = emailBodyRow.indexOf(delimiter);
            System.debug(LoggingLevel.ERROR, ':::::::delimiterIndex = ' + delimiterIndex);            
            if (delimiterIndex != -1) {
                String emailFieldName = emailBodyRow.substringBefore(delimiter);
                String emailFieldValue = emailBodyRow.substringAfter(delimiter);              
                
                emailFieldName = trim(emailFieldName);
                emailFieldValue = trim(emailFieldValue);                
                
                emailFieldNameToValueMap.put(emailFieldName, emailFieldValue);
            }
        }
        
        return emailFieldNameToValueMap;
    }

Hey, try above. it should give you all rows, with name and value sepearted by ':'. Modify as needed.
This was selected as the best answer
Onur Kaya 9Onur Kaya 9
Thank you very much for your response Vishwajeet.