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
badrul Hassanbadrul Hassan 

Its urgent ! How to write Batch apex class of this code ?

Public  class AccountSelectClassController3{
public List<wrapLead> wrapLeadList {get; set;}
    public List<Lead> selectedContacts{get;set;}
    Public String selectId {get;set;}
        
         public AccountSelectClassController3(){
         body = apexpages.currentpage().getparameters().get('att');
     if(wrapLeadList == null) {
            wrapLeadList= new List<wrapLead>();
            for(Lead a: [SELECT Name,FirstName,LastName,Email,Title,Company FROM Lead ORDER by Name ASC]) {
                // As each Account is processed we create a new wrapAccount object and add it to the wrapAccountList
                wrapLeadList.add(new wrapLead(a));
            }
        }
        normalList = true;
        selectedList = false;
        body = '';

//conId = ApexPages.currentPage().getParameters().get('Id');              
//EmailCon =[Select email from lead where Id=:conId ].email;
 //to = EmailCon ;


    }
  

     
    public void processSelected() {
        AddRecep = '';
        selectedContacts = new List<Lead>();
      
   
        for(wrapLead wrapLeadObj : wrapLeadList) {
            if(wrapLeadObj.selected == true) {
                selectedContacts.add(wrapLeadObj.acc);
                if (AddRecep == '') {
                    AddRecep = wrapLeadObj.acc.Email;
                } else {
                    AddRecep += ';' + wrapLeadObj.acc.Email ;
                }
            }
         
        }
      
    }
    public class wrapLead {
        public Lead acc {get; set;}
        public Boolean selected {get; set;}
 
        public wrapLead (Lead a) {
            acc = a;
            selected = false;
        }
    } 
}

 
Pankaj_GanwaniPankaj_Ganwani
Hi Badrul,

Can you please let us know what exactly you want to accomplish in batch apex?

Thanks,
Pankaj
badrul Hassanbadrul Hassan
fetch all lead and with this seleted processSelected (lead) display in textbox
badrul Hassanbadrul Hassan
exception you are getting.Too many rows 50001?
I want to display records more then 50000 recods .
 
Pankaj_GanwaniPankaj_Ganwani
Hi Badrul,

I don't this there is a way to pass values from batch class to vf controller. You need to put some filter in SOQL to limit the records retrieved.
badrul Hassanbadrul Hassan
Hi Pankaj,

How can we write batch Apex of this given code.
this code showning an Error!!!!
System.LimitException: Too many Email Invocations: 1

Please go through this code...

Thanks,
Regards,
Badrul Hassan
req.setMethod('POST');
        req.setHeader('Content-Type', 'application/x-www-form-urlencoded');
        SendmailUtils.Emailtemplate emailtmp=new SendmailUtils.EmailTemplate();
        emailtmp.emailTemplate=bdy.escapeHtml4();
        if(Contactlists.size() == 0)
        {
            ReturnContactList([SELECT Name,FirstName,LastName,description,Email,Title,Company,ID,phone FROM Lead where email=:Emailcon LIMIT 1]);
        }
        string isQue='0';
        req.setBody('AUCode='+aucode+'&SOrgID='+ocode+'&Subject='+sbj+'&To='+too+'+&Bcc=&contacts='+JSON.serialize(Contactlists)+'&Body='+JSON.serialize(emailtmp)+'&contents='+JSON.serialize(contentCategoryIDs)+'&IsQueue='+isQue); 
      
        try {
            res = http.send(req);
     
            if (res.getBody() != null) {
                if(isQue=='0')
                {
                    List<SendmailUtils.EmailTemplateListData> emailLists=new List<SendmailUtils.EmailTemplateListData>();
                    emailLists=(List<SendmailUtils.EmailTemplateListData>)json.deserialize(res.getbody(),List<SendmailUtils.EmailTemplateListData>.class);
                    String userName = UserInfo.getUserName();
                    User activeUser = [Select Email From User where Username = : userName limit 1];
                    String userEmail = activeUser.Email;
                    for(SendmailUtils.EmailTemplateListData emailData: emailLists)
                    {
                        if(emailData.To != null || emailData.To != '')
                        {
                            Messaging.SingleEmailMessage emails = new Messaging.SingleEmailMessage(); 
                            List<String> sendTo = new List<String>();
                            sendTo.add(emailData.To);
                            // System.debug ( 'emailData.To' +emailData.To);
                            emails.setToAddresses(sendTo);
                            emails.setSubject(emailData.Subject);
                            if(emailData.Body!=null)
                            emailData.Body = emailData.Body.unescapeHtml4();
                            emails.setHtmlBody(emailData.Body);                         
                            emails.setReplyTo(userEmail);

        -----------:  Error shows in this below line:------         
   
     Messaging.SendEmailResult [] resSentEmail= Messaging.SendEmail(new Messaging.SingleEmailMessage[] {emails});  

                            for ( Messaging.sendEmailResult result : resSentEmail ) {
                                if ( !resSentEmail[0].isSuccess () ) {
                                  //  System.debug ( 'result' +result  );
                                }        
                            }