• sesidhar ponnada 8
  • NEWBIE
  • 0 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 1
    Replies
public class BatchInsertionExtension {

    sample_request__c smpreqObj;
    public List<BatchWrapper> batchWrpprList{set;get;}
    public List<batch__c> delList;
    public List<SelectOption> options {set;get;}
    public Integer rmvBatchIndex{set;get;}
    public String delBatchId{set;get;}
    Public boolean tableFlag{set;get;}
    Public boolean msgFlag{set;get;}
    public static integer delBatchCount=0; 
    Public Id samReqId;
    
    
    public BatchInsertionExtension(ApexPages.StandardController controller) {
    samReqId = controller.getid();
    smpreqObj = [select id,Product_1_Name__c,Product_2_Name__c,Product_3_Name__c,Product_4_Name__c from sample_request__c where id =:controller.getid() ];
    options = new List<SelectOption>();
   
    batchWrpprList = new List<BatchWrapper>(); 
    
    batchWrpprList = QueryBatch();
    delList = new list<batch__c>();
  
        
    if(batchWrpprList.size()>0)
    {
     tableFlag=true;
    }
    else
    {
    tableFlag=false;
    }
    
    // Adding select list options
    
    options.add(new SelectOption('-None-','-None-'));
    If(smpreqObj.Product_1_Name__c!=null && !string.isblank(smpreqObj.Product_1_Name__c))
        options.add(new SelectOption(smpreqObj.Product_1_Name__c,smpreqObj.Product_1_Name__c));
    If(smpreqObj.Product_2_Name__c!=null && !string.isblank(smpreqObj.Product_2_Name__c))
    options.add(new SelectOption(smpreqObj.Product_2_Name__c,smpreqObj.Product_2_Name__c));
    If(smpreqObj.Product_3_Name__c!=null && !string.isblank(smpreqObj.Product_3_Name__c))
    options.add(new SelectOption(smpreqObj.Product_3_Name__c,smpreqObj.Product_3_Name__c));
    If(smpreqObj.Product_4_Name__c!=null && !string.isblank(smpreqObj.Product_4_Name__c))
    options.add(new SelectOption(smpreqObj.Product_4_Name__c,smpreqObj.Product_4_Name__c));
 
    }
    
    public class BatchWrapper
    {
      Public String selectedStr{get;set;}
      Public String batchStr{get;set;}
      Public String indexStr{set;get;}
      public String IdStr{set;get;}     
    
    }
    
    
    public void addBatch()
    {
       BatchWrapper btIns = new BatchWrapper();
       btIns.selectedStr='-None-';
       btIns.indexStr= String.valueOf(batchWrpprList.size());
       system.debug('check add'+btIns.indexStr);
       batchWrpprList.add(btIns); 
       tableFlag=true;
    
    
    }
    
    public void removeBatch()
    {
    
    integer indexCount=  rmvBatchIndex- 1;
    batchWrpprList.remove(indexCount);
   
   
      if(!String.isBlank(delBatchId))
      {
       batch__c btObj = new batch__c(id=delBatchId);
       try
       {
        delete btObj ;
        
       }
       catch(dmlexception ex)
       {
        msgFlag=true;
        apexpages.addMessages(ex);
        
       }
       catch(exception e)
       {
        msgFlag=true;
        apexpages.addMessages(e);
        
       }
      
      
      } 
   // delCount = delCount+1;
    }
    
    public void saveBatch()
    {
     List<batch__c > btUpdList = new List<batch__c >();
        
        for(BatchWrapper batchIns:batchWrpprList)
        {
          batch__c btObj = new batch__c();
         If(!String.isBlank(batchIns.IdStr))
         {
              btObj.id = batchIns.IdStr;
         }
          btObj.batch__c= batchIns.batchStr;
          btObj.Product__c = batchIns.selectedStr;
          btObj.Sample_Request__c =samReqId ;
          btUpdList.add(btObj);
        
        }
        
        try
        {
          upsert btUpdList;
          batchWrpprList.clear();
          batchWrpprList = QueryBatch();
          apexpages.Message msg = new Apexpages.Message(ApexPages.Severity.Info,'Batch Details Saved');
          apexpages.addmessage(msg);
        }
        catch(dmlexception ex)
        {
         msgFlag=true;
         apexpages.addMessages(ex);
         
        }
        catch(exception e)
        {
         msgFlag=true;
         apexpages.addMessages(e);
         
        }
        
    
    }
    
    public List<BatchWrapper> QueryBatch()
    {
      List<BatchWrapper> currbatchWrpprList = new List<BatchWrapper>();
    
   for( batch__c currBatchList : [select id, Name,batch__c,Product__c,Batch_Identifier__c from batch__c where Sample_Request__r.id=:samReqId ] )
   {
       BatchWrapper btIns = new BatchWrapper();
       btIns.selectedStr=currBatchList.Product__c;
       btIns.indexStr= String.valueOf(currbatchWrpprList.size());
       system.debug('Check 12121'+btIns.indexStr);
       btIns.IdStr= currBatchList.id;
       btIns.batchStr=currBatchList.batch__c;
       currbatchWrpprList.add(btIns); 
   
   }
   
   return currbatchWrpprList;
    
    
    }
    

}
public with sharing class productsinfo {

    public list<wrapper> wrapperlist{get;set;}
    public Sample_Request__c smp{get;set;}
    Public Id recordID{get;set;}
    public List<SelectOption> selectedlistoptions {set;get;}
    public String rowNumber {set;get;}
    public string BatchId{set;get;}
       
    public productsinfo(ApexPages.StandardController controller) {
   
    selectedlistoptions = new list<SelectOption>();
    recordID = controller.getid();
    smp=[ select Product_1__r.name,Product_2__r.name,Product_3__r.name,Product_4__r.name from Sample_Request__c WHERE id =: recordID];
    wrapperlist = new list<wrapper>();
    for( Batch__c BatchList : [select id, Name,batch__c,Product__c,Batch_Identifier__c from batch__c where Sample_Request__r.id=:recordID ] )
    {
       wrapper wrap = new wrapper();
       wrap.selectedproducts=BatchList.Product__c;
       wrap.indexnumber= String.valueOf(wrapperlist.size());
       wrap.extId = BatchList.Batch_Identifier__c;
       wrap.batchnumber=BatchList.batch__c;
       wrapperlist.add(wrap); 
   
    }
    selectedlistoptions.add(new SelectOption('-None-','-None-'));
    If(smp.Product_1__r.name!=null && !string.isblank(smp.Product_1__r.name))
        selectedlistoptions.add(new SelectOption(smp.Product_1__r.name,smp.Product_1__r.name));
    If(smp.Product_2__r.name!=null && !string.isblank(smp.Product_2__r.name))
    selectedlistoptions.add(new SelectOption(smp.Product_2__r.name,smp.Product_2__r.name));
    If(smp.Product_3__r.name!=null && !string.isblank(smp.Product_3__r.name))
    selectedlistoptions.add(new SelectOption(smp.Product_3__r.name,smp.Product_3__r.name));
    If(smp.Product_4__r.name!=null && !string.isblank(smp.Product_4__r.name))
    selectedlistoptions.add(new SelectOption(smp.Product_4__r.name,smp.Product_4__r.name));
    
    
    }

    public void addBatch(){
              if(wrapperlist == null)
              wrapperlist = new List<wrapper>();
              wrapperlist.add(new wrapper());
    }
    
    public void deleteRow(){
      
              String rowNumber = ApexPages.currentPage().getParameters().get('deleteRowNo');
              if(rowNumber != null && wrapperlist != null && !wrapperlist.isEmpty())
              wrapperlist.remove(Integer.valueOf(rowNumber));
              
              if(!String.isBlank(BatchId)){
      
              Batch__c bat = new Batch__c(id=BatchId);
             {
              delete bat;
             }
          }
    }
       
    public void savebatch(){
    
             list<Batch__c> blist = new list<Batch__c>(); 
             for(wrapper bt: wrapperlist){
             Batch__c   bat= new Batch__c();
             If(!String.isBlank(bt.extId))
             {
              bat.id = bt.extId;
             } 
             bat.batch__c= bt.batchnumber;
             bat.Product__c =bt.selectedproducts;
             bat.Sample_Request__c =recordID ;
    
             blist.add(bat);
         
        }
             insert blist;
    } 
   

   public class wrapper{
   
              Public String selectedproducts{get;set;}
              Public String batchnumber{get;set;}
              Public String indexnumber{set;get;}
              public String extId{set;get;}     
              public Batch__c bat{get;set;}
    }

}
what is batch apex and what are its uses?
what is batch apex and what are its uses?