+ Start a Discussion
sailersailer 

Email thorugh the Batch Apex and Assigning the subjcet with the Ids of particular record

Hi Everyone,
I need to send the email by appending  id in the subject.
I wrote the code ,in my query it pull 2 records and send out the mail for that two records ,but its takes only one id in the subject for the two mails that got triggered

Code is below.
global class TimeRecordReminder implements Schedulable
{
public List<Property_Obj__c> usr{get;set;} //
public List<String> usr_email{get;set;}
public Map<string,string> Map_usr{get;set;}
public List<Property_Obj__c> Ids{get;set;}
//public Property_Obj__c u;
public String idsvalue;

global void execute(SchedulableContext ctx)
{
        usr=new List<Property_Obj__c>();
        usr_email=new List<String>();
        usr.clear();
        usr_email.clear();
        Ids=[Select id from Property_Obj__c where Mail_Response__c=true ];
        usr=[select Id, Name,Mail_Response__c,Listing_Sales_Associate_Email__c from Property_Obj__c where Mail_Response__c=true AND Id=:Ids ];
        Map_usr=new Map<string,string>();
        for(Integer i=0;i<=usr.size();i++)
        {
        for(Property_Obj__c u:usr)
        {
           
            system.debug('_________id______'+u.id+'___________Email______________'+u.Mail_Response__c+'_________DATE________'+u.Name);
            Map_usr.put(u.id,u.Listing_Sales_Associate_Email__c);
            idsvalue=u.Id;
            if(u.Listing_Sales_Associate_Email__c!=null)
                usr_email.add(u.Listing_Sales_Associate_Email__c);
              
               
        }
       if (usr_email != null && usr_email.size() > 0)
       {
      
          System.debug('Size of the List Mail__________________ '+ usr_email.size());
           sendmail(usr_email);
       }
        }
}

public void sendmail(List<String> str)
{
    Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
    string [] toaddress=str;
    String[] ccAddresses=new String[]{'abc@gmail.com'};
    email.setSubject('Mass Email u.Id'+idsvalue);
    //email.setTemplateId('BC');
    email.setHtmlBody('Dear Sir /Madam,<br/><br/> Hello <br/><br/>Sincerely,<br><br/><br/>Date :'+string.valueof(system.today()));
    email.setToAddresses(toaddress);
    email.setCcAddresses(ccAddresses);
    Messaging.sendEmail(New Messaging.SingleEmailMessage[]{email});
   


}

Pl help me out or suggest ant alternative
Thanks for the help.

Regards,
Sailer
Ashish_SFDCAshish_SFDC
Hi Sailer, 


Do you mean its processing the 1st record in the list only???

Or is it processing all the records in the List and Sending Emails but Only in the Subject it is adding the ID of the 1st record in the list?

Can you print the records from the list by doing a System.Debug and see how it is saving records. 


Regards,
Ashish