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
AmarjeetAmarjeet 

Test Coverage 71%

Unable to cover highlighted part of the code in the test class.

List<Messaging.SendEmailResult> results =  Messaging.sendEmail(
                                                       new List<Messaging.SingleEmailMessage> {singleEmailMsg});

              if (results[0].success) {
           
                Date d = System.today();
                .....................
                 
                String myDate = myDT.format('yyyy-MM-dd');
                Attachment a = new Attachment(parentId = Order.id, name=myDate+'|'+dTime+' '+Order.Name +' '+ 'Body Email', body = Blob.valueof(emailBody));
                insert a;
                PageReference pgRef = new PageReference('/' + Order.Id);
                pgRef.setRedirect(true);
                return pgRef;
           
            } else {
                ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Error sending Email Message. Details = ' + results.get(0).getErrors()[0].getMessage()));
                return null;
            }