+ Start a Discussion
Raghvendra JhaRaghvendra Jha 

"SingleEmailMessage" API is not logging as activity

I’m using “SingleEmailMessage” api to sending an email but activity is not logging when we set “setSaveAsActivity” attribute true. It is throwing an exception i.e. “System.EmailException: SendEmail failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [Priority]: [Priority]”. Same piece of code working all the other classes but throwing an exception for a specific class. I’m using below code.

Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
mail.setSenderDisplayName('SalesforceLogin Test');
mail.setSubject('Subject Test1234');
mail.setSaveAsActivity(true); //add mail to the activity history
mail.setHtmlBody('Hi! Salesforce user');
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
Plz Check version of class where it is working and where it is not working .. might be diffrence