0

i wrote a Batch apex class, and i will fetch the all Account Records, But in account having Phone value is Null for Some Records, Those Records will be send to Admin user Email, How to do this Scenario in salesforce using Batch apex class.

1 Answer 1

0

I have to say that this is a very basic thing which you have asked. You have to query account records in the start method of the batch class and make sure you have been filtering the records based on the Phone field.

query = 'SELECT Id, Name FROM Account WHERE Phone = null';

In the execute method of your batch class, you can send an email. If there are less number of records then email can be sent in the finish() method of the batch. For that, you will have to use Database.Stateful interface.

In the email body, you have to send account names with a link to the record in Salesforce. So html body should be generated with the name and an hpyerlink.

<a href="{sf_instance_url}/{account.Id}"> {account.Name} </a>

You just need to write a batch and then send the email in the execute method. Since you are sending email to an internal user then it won't count against your SingleEmailMessage limits.

Check the following trailhead units where you can learn about batch apex and email from apex concepts.

Sending Email From Apex

Batch Apex Example

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .