+ Start a Discussion

Need help

Hi guys first of all thanks to all the people here they always help alot!

i have tos end an email notification to multiple users and each user there will be multiple records related

so in the email to each user will be just like below:


user1 recieves email.....[30 records based on some criteria]

user2 recieves email.....[30 records]


i am able to fetch the records all i to do is sent email and for that i am not getting how i can put all the emails and related records to one email in MAP or LIST? please help me my code is below

List<GSQM_ESH_Audiometry__c> personsResponsible = new List<GSQM_ESH_Audiometry__c>();
    Set<String> personIDSet = new Set<String>();
    Set<String> audiometryIDSet = new Set<String>();
    Map<String, String> personIDAudioID = new Map<String, String>();
    global void execute(SchedulableContext sc) {
        Map <Id,Id> audiometryObj = new Map<Id,Id>();
        for(GSQM_ESH_Audiometry__c obj : [SELECT Id, Person_Responsible_for_Assessment__c FROM GSQM_ESH_Audiometry__c
                                          WHERE Person_Responsible_for_Assessment__c!=null]){
            audiometryObj.put(obj.Id, obj.Person_Responsible_for_Assessment__c);
        list<String> email = new list<String>();
        Map<Id,String> usersObj = new Map<Id,String>();
        for(user userObj: [SELECT Id,email from user where Id=:personIDSet]){
        list<String> employeeName = new List<String>();
        list<GSQM_ESH_Employee_for_Audiometry_Test__c> audiometryListObj = new list<GSQM_ESH_Employee_for_Audiometry_Test__c>();
        Map<String, list<GSQM_ESH_Employee_for_Audiometry_Test__c>> audiometryTest= new Map<String, list<GSQM_ESH_Employee_for_Audiometry_Test__c>>();
        for(GSQM_ESH_Employee_for_Audiometry_Test__c obj : [SELECT userID__c, Employee_Name__c, Audiometry__c FROM
                                                           WHERE Audiometry__c IN:audiometryObj.keyset()
                                                           and Employee_Name__c!=NULL and Next_test__c = Next_MONTH]){

                  //i have to put this email1 and employee names related to one email in MAP or some list so then i can send email in bulk
                   String email1 =usersobj.get(obj.userID__c);