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
Felipe DiasFelipe Dias 

Sending an object list through e-mail via Apex

Hello everyone,

 

I created a batch class that has a list of some records of a custom object. And I want to send this list in an e-mail.

 

I tried using Workflow rules, but, it sends one e-mail for each record. What I want is to send one single e-mail with all records and its data fields, just like a table.

 

Here's the batch class

 

 

global class ticketClassBatch implements Database.Batchable<Ticket__c>, Database.AllowsCallouts {
Ticket__c[] Query; public ticketclassBatch(){ Query = [SELECT name, id, FROM ticket__c WHERE ticket__c.paid__c =: FALSE]; Return; } global iterable<Ticket__c> start(database.batchablecontext BC){ System.Debug('Records changed: ' + String.valueof(Query.size())); return(Query); } global void execute(Database.BatchableContext BC, List<Ticket__c> tickets){ for(ticket__C inf : tickets){ inf.alert__c = TRUE; } Update ticket; } global void finish(Database.BatchableContext BC){ } }

 

I want to send all records from this list  "Tickets" in the e-mail with it's name, and others fields.

 

Anyone knows how?

 

Thanks! 

 

Felipe Dias.

 

Dobby has no master. Dobby is a free elf.



Best Answer chosen by Admin (Salesforce Developers) 
kirkevonphillykirkevonphilly

Rather than clicking on the "today" link type in the word "today" within the box so that it remains dynamic.  

 

You'd have two filters on the report:

Pay day less or equal "today"

Paid = false

All Answers

kirkevonphillykirkevonphilly

How many rows are returned by your query?  Does the scenario allow you to create a standard report and use the report scheduler interface to send the email?  Might save you some code.

Felipe DiasFelipe Dias

An avarage of 30 row, but it can be more than that.

 

I'm not sure if it can help because I want to do two verifications for this list.

If the pay day of the ticket has already passed and if the ticket wasn't paid. Like:

 

If ( ticket__c.pday__c <= (date.Today()) &&  ticket__c.paid__c = =FALSE)     Then bring it on the list.

 

The filter that the report provides, lets me use both verifications but the first one appears like this 
"Pay day less or equal "05/02/2013"  even if I click on the "today". 

Maybe when I excecute this report tomorrow, the date will change, but I'm not sure because it appears 05/02/2013 instead of today.

 

 

kirkevonphillykirkevonphilly

Rather than clicking on the "today" link type in the word "today" within the box so that it remains dynamic.  

 

You'd have two filters on the report:

Pay day less or equal "today"

Paid = false

This was selected as the best answer
Felipe DiasFelipe Dias

I find out how to do it using the report.

Thanks for your help!