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

Can I Use PlainTextBody with HtmlBody In The Same Time?

This is my code:
            myPlainText = '';
            myPlainText = email.plainTextBody;
            String myHtmlText = '';
            myHtmlText = email.htmlBody;
            string rst;
             Pattern p1 = Pattern.compile('Buyer\\s*information[\\s\\S]+?<br>([\\s\\S]*?)</font>');
            Matcher m1 = p1.matcher(myHtmlText);
            if (m1.find()) {
             rst ='(<[^>]*>)','');          
            Pattern p2 = Pattern.compile('Invoice ID:([\\d]{7})');
            Matcher m2 = p2.matcher(myPlainText);
            if (m2.find()) {
            string OrderNumber =;
            // New PaypalRecord object to be created - set Shipping_Address__c and OrderNumber etc. to object
            // dummy values for simplicity
            List<PayPal_Record__c> NeedLists = new  List<PayPal_Record__c>();
            PayPal_Record__c Pplr;
            Pplr.CustomerName__c = rst;
            Pplr.OrderNumber__c = OrderNumber;

My question: when i debug these code, only can running one of regex, which means if i grab OrderNumber successful, the CustomerName will failed.All in all, i can't successful pass these of two regex together.

I don't know why? because I test single by single is fine,,,,,but together always said no match found......
Hi Sales Manager ,

You can not use both ,you need to choose either plainTextBody or htmlBody .