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
ForceLoverForceLover 

sending Email through Apex

  I have a custom object  Position__c everyday new positions will add to the object .I have 6 users. i want to send the position details that are created recently (today) to all the users in a single email.how can i achieve this.any help appreciated.

 

Thanks,

Anil

Best Answer chosen by Admin (Salesforce Developers) 
colemabcolemab

If using a Visualforce template, you can simply use <apex:repeat> to iterate over the list.

 

If using a plain text email or HTML email built from string in apex, you can use the for loop to iterate over the object.

All Answers

colemabcolemab

If they are all paying users, you may want to consider just creating a report and scheduling it to email to them every day . . .

ForceLoverForceLover

Thanks Colemab for replying, i'm developer free edition those are all not paying users.i want to send email through apex either from a class with schedular or batch apex and scheduling it.

 

I stuck up how to add the position details that are created today to the email body.

 

 

 

                                                   

colemabcolemab

You need to write an apex class that will query for the newly created entries in the DB for that object.

 

In that class, you will need SOQL to query for that data and populate a list.  I recommend that you use the force.com explorer to test / create your SOQL query.   Then you can copy and paste it into your apex class.

 

You may need another query or extra details in you query if you need totals / aggregate amounts

 

Then you will need to use your apex class to send an email the users in question.

 

Once all of that is done, write a schedulable / wrapper class then use execute anonymous to schedule the class to run forever.

 

 

ForceLoverForceLover

It's perfect Colemab, my requirement is, the Email body should contain all positions details that are created recently.I.e if today  i created 10 records in position object the Email should contain all 10 records ..

colemabcolemab

If using a Visualforce template, you can simply use <apex:repeat> to iterate over the list.

 

If using a plain text email or HTML email built from string in apex, you can use the for loop to iterate over the object.

This was selected as the best answer