If Answer__c
is not a child of some common parent object, then you are going to need to add some sort of sessionId__c
field to Answer__c
where all answers for a given user session are implicitly related to each other by a common sessionId__c
.
Given that, if you know when the session is completed, you could initiate one of:
- Apex Queueable job that looked for
Answer__c
with the same sessionId__c collecting them into a list
- A Visual WorkFlow that in turn called an Apex
@invocable
method that is either passed the sessionId or the actual list of Answer__c
. This Visual Workflow can be started from your controller and need not involve any user interactions
- A Process Builder flow triggered by DML on some
Session__c
custom object that in turn calls @invocable
Apex that does the same list assembly as above
- Let your controller do the work itself and read the
Answer__c
for the given session
One way or another, since the DML events on Answer__c
occur over time for some user session, then you need to signal something when the session is over to collect up the answers and use Apex to send the email.
answer__c
rollup to any parent record? You're going to need to issue emails on some consolidation object