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
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.setTargetObjectId('003o000000KWuRu');
mail.setSenderDisplayName('SalesforceLogin Test');
mail.setSubject('Subject Test1234');
mail.setSaveAsActivity(true); //add mail to the activity history
mail.setBccSender(false);
mail.setUseSignature(true);
mail.setHtmlBody('Hi! Salesforce user');
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
viruSviruS
Plz Check version of class where it is working and where it is not working .. might be diffrence