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
Ankit BobdeAnkit Bobde 

External Entry Point error

My test class is giving an error as attempt to dereference a null object..... external entry point

here is my class /*
* This class is created to Create bulk Leads  
* Taking data from previous operations Client
* The required Operations Client's data is given through Custom Settings @line 32
* Created By Ankit
*/

global class AMCLeadCreationBatch implements Database.Batchable<sObject>,Database.AllowsCallOuts,Database.Stateful {
    
    global string query;
    global string mobile, rocName,phoneNumber, ownerName,enquiryFor,ownerEmail, leadContact, smsTemplate='', todaydt,enqFor,newLeadEnquiryFor;
    global DateTime dt, scheduleDate;
    global date todayDate,toDate,fromDate;
    Integer limitNo,tempSize=0,maxSize;
    list<Lead> newLeadList = new list<Lead>();
    list<Lead> listOfLeads = new list<Lead>();
    list<Operation__c> newOperationList = new list<Operation__c>();
    //list<id> userIDs = new list<Id>{'00590000000myQN','00590000000myQm','00590000000oVw0'};
    list<String> userIDs = new list<String>();
    String idStrings;
    String userInLoopID=null;
    String tempUserId;
    
    global AMCLeadCreationBatch(){
        dt = system.now();  
        todayDate = dt.date();
        //todayDate = date.newInstance(dt.year(), dt.month(), dt.day());
        todayDt = date.today().format();
     
        system.debug('-todayDt-' + todayDt+'-todayDate-'+ todayDate);
        
       for(BulkLeadCreation__c newList: [Select ROC_Name__c,New_Lead_Enquiry_For__c,From_Date__c,To_Date__c,UserIDs__c,Enquiry_For__c,Limit__c from BulkLeadCreation__c where Name = '1']){
            Integer tempInt;
            newLeadEnquiryFor = newList.New_Lead_Enquiry_For__c;
            enqFor = newList.Enquiry_For__c;
            tempInt = Integer.valueof(newList.Limit__c);
            limitNo = tempInt;
            idStrings = newList.UserIDs__c;
            fromDate = newList.From_Date__c;
            toDate = newList.To_Date__c;
            if(newList.ROC_Name__c != null){
                rocName = newList.ROC_Name__c;
            }
        }
        if(idStrings != null){
            userIDs=idStrings.split(',');
        }
        system.debug('-userIDs from CS-'+userIDs+userIDs.size());
        
          
          listOfLeads = [Select isBulkcreated__c,isConverted,BMCID__c from lead where isBulkcreated__c=:true AND Enquiry_For__c =: newLeadEnquiryFor AND isConverted=:false  AND Created_Date__c < :system.today()-365];
          system.debug('-listOfLeads-'+listOfLeads+listOfLeads.size());
          set<String> stringList= new set<String>();
          string BMCIDString;
         // system.debug('-system.today()-365-'+system.today()-365);
          
          if(listOfLeads.size()>0){
              for(Lead tempList : listOfLeads){
                  BMCIDString = tempList.BMCID__c;
                  stringList.add(BMCIDString);
                  system.debug('-stringList-'+stringList);
              }
          }
          system.debug('-stringList out of the loop-'+stringList+stringList.size());
          
          newOperationList = [Select isBulkCreated__c from Operation__c where Name IN : stringList];
          list<operation__c> tempOpList = new list<Operation__c>();
          system.debug('-newOperationList-'+newOperationList+newOperationList.size());
          
          if(newOperationList.size()>0){
              for(Operation__c tempOp:newOperationList){
                  tempOp.isBulkCreated__c = false;
                  tempOpList.add(tempOp);
              }
          }
          system.debug('-tempOpList-'+tempOpList+tempOpList.size());
          if(tempOpList.size()>0){
              update tempOpList;
          }
    }
    
    global Database.Querylocator start(Database.BatchableContext bc){
        
        
        if(rocName!=null)
        {
            query ='Select id,Contact_Name__c,ContactCCEmail__c,Contact_Email__c,Phone_Number__c,Enquiry_for__c,Contact_FirstName__c,Contact_LastName__c,Contact_Salutation__c,'+
               'City__c,ROC_Name__c,Incorporation_Date__c,Auth_Capital__c,Paid_Up_Capital__c,'+
               'Name,New_Company_Name__c,Company_Extention__c,CreatedDate,Owner_Name__c,BDE_Name__c from Operation__c'+
               ' where Enquiry_for__c =: enqFor AND Incorporation_Date__c >= :fromDate AND Incorporation_Date__c <= :toDate AND ROC_Name__c =:rocName limit : limitNo';
        }else{
            query ='Select id,Contact_Name__c,ContactCCEmail__c,Contact_Email__c,Phone_Number__c,Enquiry_for__c,Contact_FirstName__c,Contact_LastName__c,Contact_Salutation__c,'+
               'City__c,ROC_Name__c,Incorporation_Date__c,Auth_Capital__c,Paid_Up_Capital__c,'+
               'Name,New_Company_Name__c,Company_Extention__c,CreatedDate,Owner_Name__c,BDE_Name__c from Operation__c'+
               ' where Enquiry_for__c =: enqFor AND Incorporation_Date__c >= :fromDate AND Incorporation_Date__c <= :toDate limit : limitNo';
        }
                         
        system.Debug('---in CLass Query contains Before return statement---'+ query);
        return Database.getQueryLocator(query);               
    }
    
    global void execute(Database.BatchableContext bc, list<Operation__c> scope){
        try{
            
            list<Operation__c> newOpList = new list<Operation__c>();
            list<Operation__c> updateOpList =new list<Operation__c>();
            
            newOpList = [Select id,isBulkCreated__c from Operation__c where id IN : scope];
            
            for(Operation__c opList: newOpList){
                opList.isBulkCreated__c = true;
                updateOpList.add(opList);
            }
            update updateOpList;
            system.debug('--updateOpList--'+updateOpList);
            
            System.debug('---Scope--'+ Scope);
            dt = system.now();
            todayDate = date.newInstance(dt.year(), dt.month(), dt.day());
            for(Operation__c scheduledoperation : scope){
                
                Lead newLead = new Lead();
                Integer size=userIDs.size();
                boolean flag=false;
                
                for(String tempId:userIDs){
                    tempSize=tempSize+1;
                    if(userIDs.size()==1){
                        tempSize=0;
                    }
                    system.debug('--tempSize--'+tempSize);
                    if(userInLoopID==tempId){
                        newLead.User__c = userIDs.get(tempSize);
                        newLead.OwnerID = userIDs.get(tempSize);
                        userInLoopID = userIDs.get(tempSize);
                        if(tempSize==userIDs.size()-1){
                            maxSize=1;
                            system.debug('-maxSize-'+maxSize);
                        }
                        system.debug('-tempSize-'+tempSize);
                        tempSize=0;
                        flag=true;
                        break;
                    }
                }
                if(flag==false){
                        newLead.User__c = userIDs.get(0);
                        newLead.OwnerID = userIDs.get(0);
                        userInLoopID=userIDs.get(0);
                        tempSize=0;
                        maxSize=0;
                        system.debug('-userInLoopID in else if-'+userInLoopID);
                }
                
                if(maxSize==1){
                    userInLoopID=null;
                    system.debug('-userInLoopID-'+userInLoopID);
                }
                
                newLead.Salutation = scheduledoperation.Contact_Salutation__c;
                newLead.CCEmail__c=scheduledoperation.ContactCCEmail__c;
                newLead.LastName = scheduledoperation.Contact_LastName__c;
                newLead.FirstName = scheduledoperation.Contact_FirstName__c;
                newLead.Contact_Name__c = scheduledoperation.Contact_Name__c;
                newLead.Email = scheduledoperation.Contact_Email__c;
                newLead.Phone = scheduledoperation.Phone_Number__c;
                newLead.Enquiry_For__c = newLeadEnquiryFor;
                newLead.Created_Through__c = 'BDE';
                newLead.WorkFlowNumber__c = 1;
                newLead.CompliancePage__c = true;
                newLead.City = scheduledoperation.City__c;
                newLead.ROC_Name__c = scheduledoperation.ROC_Name__c;
                newLead.Incorporation_Date__c = scheduledoperation.Incorporation_Date__c;
                newLead.Auth_Capital__c = scheduledoperation.Auth_Capital__c;
                newLead.Paid_up_Capital__c = scheduledoperation.Paid_Up_Capital__c;
                newLead.BMCID__c = scheduledoperation.Name;
                newLead.Operation_owner__c = scheduledoperation.Owner_Name__c;
                newLead.Operations_Created_Date__c = scheduledoperation.createdDate;
                newLead.Company = scheduledoperation.New_Company_Name__c +' '+scheduledoperation.Company_Extention__c;
                newLead.BDE_Name__c = scheduledoperation.BDE_Name__c;
                newLead.isBulkcreated__c = true;
                newLeadList.add(newLead);
                
          }
    
    
        Database.SaveResult[] srList = Database.insert(newLeadList,false);
        for(Database.SaveResult sr : srList){
            if(sr.isSuccess()){
                system.debug('Successfully inserted Transaction. Transaction ID: ' + sr.getID());
            }
            else{
                for(Database.Error err : sr.getErrors()){
                    System.debug('The following error has occurred.');
                    System.debug(err.getStatusCode() + ': ' + err.getMessage());
                    System.debug('Transaction fields that affected this error: ' + err.getFields());

                }
            }
        }
        
        }catch(exception e){
            system.debug('--Exception--'+ e.getMessage());
        }  
         
    }
    
    global void finish(Database.BatchableContext BC){
        AsyncApexJob a = [Select Id, Status, NumberOfErrors, JobItemsProcessed,TotalJobItems, CreatedBy.Email
                                          from
                                          AsyncApexJob
                                          where
                                          Id =:BC.getJobId()];
         
         system.debug('--Batch Job contains--' + a);
         Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
         String[] toAddresses = new String[] {'ankit.bobde@bmcgroup.in'};
         mail.setToAddresses(toAddresses);
         mail.setSubject('Bulk : Lead Creation Batch ' + a.Status);
         mail.setPlainTextBody
         ('The batch Apex job processed ' + a.TotalJobItems +
          ' batches with '+ a.NumberOfErrors + ' failures.');
        Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
        
     }
      
    

}

 
bob_buzzardbob_buzzard
Does it give you a line number? Otherwise its going to be pretty difficutl to identify where you might hit a null pointer.
Ankit BobdeAnkit Bobde
Hey Bob ...it is not giving me the line number which is creating a problem