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
shiva1236shiva1236 

how to send an email with the count of number of records in a Standard Object

hi can anyone help me with my requirement i.e,
how to send an email with the count of number of records in a Standard Object
Rahul KumarRahul Kumar (Salesforce Developers) 
Hi Shiva,
  •  To count the number of records.
AggregateResult[] arList = [select count(id) from Event];
System.debug(LoggingLevel.INFO, arList[0].get('expr0'));

Please refer the below link for reference. hope it helps.

Please mark it as best answer if the information is informative.so that question is removed from an unanswered question and appear as a proper solution.

Thanks
Rahul Kumar
NForceNForce
HI Shiva, 
Get the count as Rahul did, and below is the code for sending email
Messaging.SingleEmailMessage message = new Messaging.SingleEmailMessage();
message.toAddresses = new String[] { 'abc@gmail.com', 'xyz@gmail.com' };
message.subject = 'Opt Out Test Message';
message.plainTextBody = 'Number of records: ' + arList[0].get('expr0');
Messaging.SingleEmailMessage[] messages =   new List<Messaging.SingleEmailMessage> {message};
Messaging.SendEmailResult[] results = Messaging.sendEmail(messages);