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
AKallAKall 

Having difficulty formatting date, and passing a string to a field.

I am having difficulty with two sections of code that are posted below. They are both from the same inbound email handler class.

The first section is meant to reformat a date in a Fedex tracking email to the SF format yyyy-mm-dd. My test emails fail...I get the following message in the failure notice email 'Invalid Integer: 10' The date appears in the email as this '10/06/2008'. The error is clearly because of the month. I have highlighted and underlined where the error is occuring.

Code:
String[] prepDate = emailBody.split('This shipment is scheduled to be sent on',0);
String[] sDate = prepDate[1].substring(0,10).split('/');
Datetime shipDate = datetime.newInstance(Integer.valueOf(sDate[2]),Integer.valueOf(sDate[0]),Integer.valueOf(sDate[1]));
Date myshipDate = date.valueOf(sDate[2]+'-'+sDate[0]+'-'+sDate[1]);

MailedPackage__c MP = [Select ID, TrackingNumber__c, Mailed__c, SignedBy__c, Test_Field__c, Delivered__c FROM MailedPackage__c Where Mailed__c = :myshipDate ];


My second problem occurs a little further down the page where I try take the traking # from the email and update the Tracking # field in SF.  The field does update, but I can never get any value other than a solid line whose length I can change based on the value I put in the substring limit.

Code:
MailedPackage__c MP = [Select ID, TrackingNumber__c, Mailed__c, SignedBy__c, Test_Field__c, Delivered__c FROM MailedPackage__c  Where Mailed__c = :myshipDate ];
  
  
 
 
 
     //retrieves tracking number from email and passes it to Tracking Number field  
     String[] prepTrack = emailBody.split('Tracking Number:',0);
     String TrackingNum = prepTrack[0].substring(0,12);
     MP.TrackingNumber__c = TrackingNum;
     update MP;