I thought this would be simple enough but apparently I can't get it to work since I'm doing something really stupid here.
- I have an account named CVB in my test org.
- I send an email to Salesforce using my email ID and with just CVB in the body.
- The Email is being read fine since the first System.debug statement does show the string as CVB.
- What my code fails to do is update the CVB account with the datetime.
The issue is with the SOQL query since I'm getting the following error in the log:
FATAL_ERROR System.QueryException: List has no rows for assignment to SObject
global class ProcessTelerikEmail implements Messaging.InboundEmailHandler {
global Messaging.InboundEmailResult handleInboundEmail(Messaging.InboundEmail email, Messaging.InboundEnvelope envelope) {
Messaging.InboundEmailResult result = new Messaging.InboundEmailresult();
String accName = email.plainTextBody;
System.debug('Account Name is:' + accName);
Datetime myDateTime = Datetime.newInstance(2015, 6, 3);
Account accs = new Account();
accs = [SELECT Id, Burn_script_run_time__c, Name from Account WHERE Name= :accName ];
System.debug('Account name is: ' + accs.Name);
accs.Burn_script_run_time__c = myDateTime ;
return result;
}
}
accName
variable value has hidden unprintable characters. Also (tip) - avoid plural variable names (accs
) when you declare as a singleton.accName.length()
; another tip - for traceability reasons, a good idea is to use a separate user seat for the inbound email context user - that way, when a record is modified, you know what 'event' did the modification (i.e., not you doing data maintenance/data loader)