I add a inbound email handler into my org to add a new record in a custom object (bt).
Sometime the mails are not processed and I don't know why. Is there a way to check the incoming mails in Salesforce?
can I enter a line in the code where the process should begin and end? Because sometimes is some text before or after the relevant points.
global class btFromEmail implements Messaging.InboundEmailHandler {
global Messaging.InboundEmailResult handleInboundEmail(Messaging.InboundEmail email, Messaging.InboundEnvelope envelope) {
Messaging.InboundEmailResult result = new Messaging.InboundEmailResult();
bt__c C = new bt__c();
if(email.plainTextBody != Null && email.plainTextBody != '') {
String[] emailBodyRows = email.plainTextBody.split('\n');
for (String bodyRow:emailBodyRows) {
String[] rowContents = bodyRow.split(':');
String label = rowContents[0].trim();
String value = rowContents[1].trim();
switch on label {
when 'Firstname' {
c.Firstname__c = value;
}
when 'Lastname' {
c.Lastname__c = value;
}
when 'Birthdate' {
c.Birthdate__c = date.valueOf(value);
}
when 'Phone' {
c.Phone_private__c = value;
}
when 'Email' {
c.E_mail_private__c = value;
}
}
}
}
insert c;
return result;
}
}
bt__c
inserted. Be sure you have apex exception emails configured correctly so any exceptions get reported to you.