You need to sign in to do that
Don't have an account?
Ajay_SF
how to parse the following text email body?
Hi! What's the best way to parse the following text email body? Email body-
I'm looking to build a List<TransactionInformation>, something like this-
This is a detailed summary of your live recurring billing transactions for the 24 hours prior to the time of this e-mail. Successful Recurring Billing Transactions: Credit Card transactions The following profiles have successfully charged customer credit cards: Profile ID: 12 Profile Name: DONOR_1 Payment Number: 5 Retry Number: 0 PNRef: BL001YY Transaction Time: 29-Apr-21 06:26 AM Amount: 50.00 Profile ID: 13 Profile Name: DONOR_2 Payment Number: 5 Retry Number: 0 PNRef: BL001XX Transaction Time: 29-Apr-21 06:26 AM Amount: 50.00 Total Number of Approved Transactions: 2 Total Approved Amount: 100.00 Declined Recurring Billing Transactions Credit Card transactions The following profiles have failed to charge customer credit cards for the current payment period: Total Number of Declined Transactions: 0 Total Declined Amount: 0.00 We thank you for your business. Sincerely, PayPal Merchant Services
I'm looking to build a List<TransactionInformation>, something like this-
public class TransactionInformation { public String ProfileID; public String ProfileName; public Integer PaymentNumber; public String RetryNumber; public String PNRef; public String TransactionTime; public Decimal Amount; }
Go with Regular Expressions in Apex. Using these will make it easier to get the "key" ("ProfileID", for example) and the value between the end of the key and the following line break.
Reference:
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_pattern_and_matcher_using.htm
RegExr.com: Very useful tool for writing proper Regular Expression patterns. Here's one that will grab the "PaymentNumber" from your email body: From there, you could use the String.right() method to remove the key, and you'll be left with just the value. All the Apex String methods can be found here (https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_string.htm).
Example: Then just use the obtained string values as per the requirement and set the relevant fields equal to the values you've derived!
Hope above information helps, Please mark as Best Answer so that it can help others in the future.
Thanks.