• jasmin05
  • NEWBIE
  • 10 Points
  • Member since 2013

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 8
    Replies
Hi,
I developed the following code in Winter 14 (sandbox) and it works correctly.
But when I deployed it to Summer 14 (production environment), I could not update the "Status__c" data.
Please help me to resolve this issue...

********** Visualforce Code************

<apex:form id="theForm">
    <apex:pageblock id="theBlock" tabstyle="Bulk_Edit__tab" mode="maindetail">
        <!-- ============================== -->
        <!-- Command Buttons                -->
        <!-- ============================== -->
        <apex:pageBlockButtons location="top">
            <apex:commandButton value="Edit" action="{!editBulk}" rendered="{!!isBulkEdit}"/>
            <apex:commandButton value="Save" action="{!saveBulk}" rendered="{!isBulkEdit}"/>
            <apex:commandButton value="Cancel" action="{!cancelBulk}" rendered="{!isBulkEdit}"/>
        </apex:pageBlockButtons>
        <apex:outputPanel >
            <apex:inputHidden value="{!tableHeight}" id="tableHeight" />
        </apex:outputPanel>
              
        <apex:outputPanel layout="block" id="refTablePanel" style="width:100%">
            <apex:outputPanel >
                <div class="hideCurrDate">
                <div id="listTableDiv" class="superTablesDiv" style="width:1500px; height:{!tableHeight}px;">
                    <table id="listTable" width="95%">
                    <!--======================-->
                    <!-- HEADER                               -->
                    <!--======================-->                       
                        <tr>
                            <!--★Column1-->
                            <th><span style="width:70px; overflow: hidden; white-space: nowrap; text-overflow: string; -o-text-overflow: ellipsis; -ms-text-overflow: ellipsis; display:block; ">
                                <apex:outputText value="Column1"/>
                                </span>
                            </th>
                            <!--★Column2-->
                            <th><span style="width:70px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; -o-text-overflow: ellipsis; -ms-text-overflow: ellipsis; display:block;">
                                <apex:outputText value="Column2"/>     
                                </span>
                            </th>
                            <!--★Status-->
                            <th><span style="width:600px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; -o-text-overflow: ellipsis; -ms-text-overflow: ellipsis; display:block;">
                                <apex:outputText value="Status"/>     
                                </span>
                            </th>
                        </tr>
                   <!--======================-->
                   <!-- DATA                                    -->
                   <!--======================-->
                        <apex:repeat value="{!reportItemList}" var="objItem">
                            <apex:variable value="{!1}" var="rowNum"/>
                            <apex:repeat value="{!objItem.itemData}" var="i" >
                                <tr onmouseover="mover(this);"  onmouseout="mout(this);">
                                    <!--★Column1-->
                                    <td class="{!if(rowNum==1,'show','hidden')}" rowspan="{!objItem.itemData.size}">
                                        <span style="white-space: normal; overflow:hidden; text-overflow: ellipsis; -o-text-overflow: ellipsis; -ms-text-overflow: ellipsis; word-wrap:break-word; display:block;">
                                            <apex:outputField value="{!objItem.mer.name}" rendered="{!if(rowNum==1,true,false)}"/>
                                        </span>
                                    </td>
                                   
                                    <!--★Column2-->
                                    <td><span style="overflow: hidden; white-space: normal; text-overflow: ellipsis; -o-text-overflow: ellipsis; -ms-text-overflow: ellipsis; word-wrap:break-word; display:block;">
                                        <apex:outputField value="{!i.Column2__c}"/>
                                        </span>
                                    </td>
                                  
                                    <!--★Status-->
                                    <td class="{!if(rowNum==1,'show','hidden')}" rowspan="{!objItem.itemData.size}">
                                        <span style="overflow: hidden; white-space: normal; text-overflow: ellipsis; -o-text-overflow: ellipsis; -ms-text-overflow: ellipsis; word-wrap:break-word; display:block;">
                                            <apex:outputField value="{!objItem.mer.Status__c}" rendered="{!if(rowNum==1,true,false)&&!isBulkEdit}"/>
                                            <apex:inputField value="{!objItem.mer.Status__c}" rendered="{!if(rowNum==1,true,false)&&isBulkEdit}" style="width:90%;"/>
                                        </span>
                                    </td>
                                </tr>
                                <apex:variable var="rowNum" value="{!rowNum + 1}"/>
                            </apex:repeat>
                        </apex:repeat>
                    </table>
                </div>
                </div>
            </apex:outputPanel>
        </apex:outputPanel>
   </apex:pageBlock>
</apex:form>


********** Apex Class Code************

public class MER_Bulk_Ext {
    //==========================================================
    // Public Fields
    //==========================================================
    public List<ReportItem> reportItemList{get; set;}
    public Boolean isBulkEdit{get; set;}
    public Integer tableHeight {get; set;}
    //==========================================================
    // Private Fields
    //==========================================================
    //Property for Paging
    @TestVisible private ApexPages.StandardSetController stdSetCntrl {get;set;}
    private Integer totalId;
   
    //================================================================
    // Constructor
    //================================================================
    public MER_Bulk_Ext(ApexPages.StandardController controller) {

        List<MER__c> merList = new List<MER__c>();
            merList = [SELECT m.name,
                         m.Status__c,
                         (SELECT i.Column2__c
                            FROM MER_Itemized_Status__r i) itemData
                     FROM MER__c m
                 ORDER BY m.name
                 ];
           
        for(MER__c m: merList){
            ReportItem objItem = new ReportItem();
            objItem.mer = m;
            objItem.itemData = m.MER_Itemized_Status__r;
        }

        this.stdSetCntrl = new ApexPages.StandardSetController(merList);
        this.stdSetCntrl.setPageSize(100);
        this.reportItemList = this.generateMERList();
        this.tableHeight =615;
    }
  
    // Inner Class Definition
    public Class ReportItem {
        public MER__c mer {get; set;}
        public List<MER_Itemized_Status__c> itemData {get; set;}
    }
   
    //---------------------------------------------------------------
    // [save] Button in Page[MER_BulkEdit]
    //---------------------------------------------------------------
    public PageReference saveBulk(){
        List<MER__c> updateMer = new List<MER__c>();
        List<MER_Itemized_Status__c> updateItem = new List<MER_Itemized_Status__c>();
        for (ReportItem mer : this.reportItemList) {
            updateMer.add(mer.mer);
            for(MER_Itemized_Status__c i:mer.mer.MER_Itemized_Status__r){
                updateItem.add(i);
            }
        }
        try {
            if (updateMer.size() > 0) {
                update updateMer;
                ★I can not get the input data from VF. Status__c is not updated.★
            }
            if (updateItem.size() > 0) {
                update updateItem;
            }
        } catch (DMLException e) {
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, e.getDMLMessage(0)));
            return null;
        }
        isBulkEdit=false;
        PageReference pgr = Page.MER_BulkEdit;
        pgr.setRedirect(true);
        return pgr;
    }
   
    //---------------------------------------------------------------
    // [Edit] Button in Page[MER_BulkEdit]
    //---------------------------------------------------------------
    public PageReference editBulk(){
        PageReference pgr = new PageReference('/apex/MER_BulkEdit');
        isBulkEdit=true;
        return pgr;
    }
   
    //---------------------------------------------------------------
    // [Cancel] Button in Page[MER_BulkEdit]
    //---------------------------------------------------------------
    public PageReference cancelBulk(){
        PageReference pgr = new PageReference('/apex/MER_BulkEdit');
        isBulkEdit=false;
        return pgr;
    }
   

   
    //==========================================================
    // Private Method
    //==========================================================
    public List <ReportItem> generateMERList() {
        List<ReportItem> customList = new List<ReportItem>();
       
        for (MER__c mer : (List<MER__c>)this.stdSetCntrl.getRecords()) {
            ReportItem merItem = new ReportItem();
            merItem.mer = mer;
            merItem.itemData = mer.MER_Itemized_Status__r;
            customList.add(merItem);
        }
        return customList;
    }
}
************************************************************************:
Thank you in advance for your help!
I created Apex Batch Class.
When I try to inport over 50,000 rows of CSV file, the following error appears.
"Batchable instance is too big".
I don't know how to resolve this issue...
The following is my batch code.


global with sharing class NSRCOR_MER_Import_Batch implements Database.batchable<string>, Database.Stateful{
    private String m_csvFile;
    private String m_batchLogId;
    Boolean isHeader = true;
    private static Integer rowCount;
    private static Integer importCount =0;
    Boolean success = true;
    String remarks = '';
  
    global NSRCOR_MER_Import_Batch(String csfFile, String batchLogId){
        m_csvFile = csfFile;
        m_batchLogId = batchLogId;
    }
    global Iterable<string> start(Database.batchableContext batchableContext){
       return new NSRCOR_MER_CSVIterator(m_csvFile,'\n');
    }
    global void execute(Database.BatchableContext batchableContext, List<string> scope)  {    
        List<NSRCOR_MER_PO__c> importPO = new List<NSRCOR_MER_PO__c>();
        List<NSRCOR_MER_PO__c> updatePO = new List<NSRCOR_MER_PO__c>();
        Integer lineNo = 0;
        Integer countInsert = 0;
        Integer countUpdate = 0;
        if (rowCount == null){rowCount =0;}
    
        // Get list of exist PO data
        Map<String,NSRCOR_MER_PO__c> poMap = new Map<String,NSRCOR_MER_PO__c>();
        for (NSRCOR_MER_PO__c rt : [SELECT id,name,PO_Title__c, Vendor_Name__c FROM NSRCOR_MER_PO__c]){
            poMap.put(rt.name, rt);
        }
        NSRCOR_MER_Import_Log__c importLog =[SELECT Nubmer_of_Rows__c FROM NSRCOR_MER_Import_Log__c WHERE Id=:m_batchLogId ];
        if(importLog.Nubmer_of_Rows__c ==null){
            rowCount = 0;
        }else{
            rowCount = Integer.valueOf(importLog.Nubmer_of_Rows__c);
        }
      
        Map<Integer,Integer> toInsertRownum = new Map<Integer,Integer>();
        Map<Integer,Integer> toUpdateRownum = new Map<Integer,Integer>();
        Map<Integer,String> poMapInsert= new Map<Integer,String>();
        Map<Integer,String> POMapUpdate= new Map<Integer,String>();
 
        for(String row : scope){
            if(isHeader){
              isHeader = false;
            }else{
              List<String> csvValues = row.split(',');
              String poName = null;
              
                // PO
                NSRCOR_MER_PO__c po     = new NSRCOR_MER_PO__c();
                if(poMap.get(this.deSanitize(csvValues[0].trim()))==null){
                    po.Name             = this.deSanitize(csvValues[0].trim());
                    po.PO_Title__c      = this.deSanitize(csvValues[1].trim());
                    po.Vendor_Name__c   = this.deSanitize(csvValues[2].trim());
                    importPO.add(po);
                    poName = po.Name;
                    poMap.put(poName, po);
                    toInsertRownum.put(countInsert,lineNo);
                    poMapInsert.put(countInsert,poName);
                    countInsert++;
                        
                }else{
                    if(poMap.get(this.deSanitize(csvValues[0].trim())).PO_Title__c != this.deSanitize(csvValues[1].trim()) ||
                       poMap.get(this.deSanitize(csvValues[0].trim())).Vendor_Name__c != this.deSanitize(csvValues[2].trim())){
                        poMap.get(this.deSanitize(csvValues[0].trim())).PO_Title__c    = this.deSanitize(csvValues[1].trim());
                        poMap.get(this.deSanitize(csvValues[0].trim())).Vendor_Name__c = this.deSanitize(csvValues[2].trim());
                        updatePO.add(poMap.get(this.deSanitize(csvValues[0].trim())));
                        toUpdateRownum.put(countUpdate,lineNo);
                        poMapUpdate.put(countUpdate,poName);
                        countUpdate++;
                    }
                }
                lineNo++;
              
            }
         
        }
      
        if(importPO!=null && importPO.size()>0){
            //insert importPO;
            Database.SaveResult[] srList = Database.insert(importPO, false);
            Integer ln = 0;
            for (Database.SaveResult sr : srList) {
                if (sr.isSuccess()) {
                    //importCount ++;             
                }else{
                    success = false;
                    // Operation failed, so get all errors              
                    for(Database.Error e : sr.getErrors()) {
                        Integer num = toInsertRownum.get(ln) + rowCount + 1;
                        //remarks = remarks + 'ERROR: Row '+ num + '; '+ 'PO No. '+  poMapInsert.get(ln)+'; '+e.getMessage()+'\n';
                        remarks = remarks + 'ERROR: Row '+ num +'; '+e.getMessage()+'\n';
                    }
                }
                ln++;
            }       
          
        }
        if(updatePO!=null && updatePO.size()>0){
           // update updatePO;
            Database.SaveResult[] srList = Database.update(updatePO, false);
            Integer ln = 0;
            for (Database.SaveResult sr : srList) {
                if (sr.isSuccess()) {
                    //importCount ++;             
                }else{
                    success = false;
                    // Operation failed, so get all errors              
                    for(Database.Error e : sr.getErrors()) {
                        Integer num = toUpdateRownum.get(ln) + rowCount + 1;
                        //remarks = remarks + 'ERROR: Row '+ num + '; '+ 'PO No. '+  poMapUpdate.get(ln)+'; '+e.getMessage()+'\n';
                        remarks = remarks + 'ERROR: Row '+ num +'; '+e.getMessage()+'\n';
                    }
                }
                ln++;
            }
        }
      
        rowCount =  rowCount + lineNo;         
        importLog.Nubmer_of_Rows__c =  rowCount;
        update importLog;

    }
    global void finish(Database.BatchableContext batchableContext){
      
      
        NSRCOR_MER_Import_Log__c importLog = [SELECT Id,Name,Status__c,Remarks__c,Import_Count__c, Nubmer_of_Rows__c FROM NSRCOR_MER_Import_Log__c WHERE Id=:m_batchLogId];
        if(!success){
            if(remarks.length() > 2000){
                importLog.Remarks__c = remarks.substring(0,2000);
            }else{
                importLog.Remarks__c = remarks;
            }
            importLog.Status__c = 'Failed';
          
        }
        //importLog.Import_Count__c = String.valueOf(importCount);
        importLog.Nubmer_of_Rows__c =0;
        Update importLog;
      
        Database.executeBatch(new NSRCOR_MER_Items_Import_Batch(m_csvFile, m_batchLogId));
      
    }
  
    private String deSanitize(String value) {
        return value.replace('#comma#',',').replace('#dbc#','"');
    }
}
Hi,
I developed the following code in Winter 14 (sandbox) and it works correctly.
But when I deployed it to Summer 14 (production environment), I could not update the "Status__c" data.
Please help me to resolve this issue...

********** Visualforce Code************

<apex:form id="theForm">
    <apex:pageblock id="theBlock" tabstyle="Bulk_Edit__tab" mode="maindetail">
        <!-- ============================== -->
        <!-- Command Buttons                -->
        <!-- ============================== -->
        <apex:pageBlockButtons location="top">
            <apex:commandButton value="Edit" action="{!editBulk}" rendered="{!!isBulkEdit}"/>
            <apex:commandButton value="Save" action="{!saveBulk}" rendered="{!isBulkEdit}"/>
            <apex:commandButton value="Cancel" action="{!cancelBulk}" rendered="{!isBulkEdit}"/>
        </apex:pageBlockButtons>
        <apex:outputPanel >
            <apex:inputHidden value="{!tableHeight}" id="tableHeight" />
        </apex:outputPanel>
              
        <apex:outputPanel layout="block" id="refTablePanel" style="width:100%">
            <apex:outputPanel >
                <div class="hideCurrDate">
                <div id="listTableDiv" class="superTablesDiv" style="width:1500px; height:{!tableHeight}px;">
                    <table id="listTable" width="95%">
                    <!--======================-->
                    <!-- HEADER                               -->
                    <!--======================-->                       
                        <tr>
                            <!--★Column1-->
                            <th><span style="width:70px; overflow: hidden; white-space: nowrap; text-overflow: string; -o-text-overflow: ellipsis; -ms-text-overflow: ellipsis; display:block; ">
                                <apex:outputText value="Column1"/>
                                </span>
                            </th>
                            <!--★Column2-->
                            <th><span style="width:70px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; -o-text-overflow: ellipsis; -ms-text-overflow: ellipsis; display:block;">
                                <apex:outputText value="Column2"/>     
                                </span>
                            </th>
                            <!--★Status-->
                            <th><span style="width:600px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; -o-text-overflow: ellipsis; -ms-text-overflow: ellipsis; display:block;">
                                <apex:outputText value="Status"/>     
                                </span>
                            </th>
                        </tr>
                   <!--======================-->
                   <!-- DATA                                    -->
                   <!--======================-->
                        <apex:repeat value="{!reportItemList}" var="objItem">
                            <apex:variable value="{!1}" var="rowNum"/>
                            <apex:repeat value="{!objItem.itemData}" var="i" >
                                <tr onmouseover="mover(this);"  onmouseout="mout(this);">
                                    <!--★Column1-->
                                    <td class="{!if(rowNum==1,'show','hidden')}" rowspan="{!objItem.itemData.size}">
                                        <span style="white-space: normal; overflow:hidden; text-overflow: ellipsis; -o-text-overflow: ellipsis; -ms-text-overflow: ellipsis; word-wrap:break-word; display:block;">
                                            <apex:outputField value="{!objItem.mer.name}" rendered="{!if(rowNum==1,true,false)}"/>
                                        </span>
                                    </td>
                                   
                                    <!--★Column2-->
                                    <td><span style="overflow: hidden; white-space: normal; text-overflow: ellipsis; -o-text-overflow: ellipsis; -ms-text-overflow: ellipsis; word-wrap:break-word; display:block;">
                                        <apex:outputField value="{!i.Column2__c}"/>
                                        </span>
                                    </td>
                                  
                                    <!--★Status-->
                                    <td class="{!if(rowNum==1,'show','hidden')}" rowspan="{!objItem.itemData.size}">
                                        <span style="overflow: hidden; white-space: normal; text-overflow: ellipsis; -o-text-overflow: ellipsis; -ms-text-overflow: ellipsis; word-wrap:break-word; display:block;">
                                            <apex:outputField value="{!objItem.mer.Status__c}" rendered="{!if(rowNum==1,true,false)&&!isBulkEdit}"/>
                                            <apex:inputField value="{!objItem.mer.Status__c}" rendered="{!if(rowNum==1,true,false)&&isBulkEdit}" style="width:90%;"/>
                                        </span>
                                    </td>
                                </tr>
                                <apex:variable var="rowNum" value="{!rowNum + 1}"/>
                            </apex:repeat>
                        </apex:repeat>
                    </table>
                </div>
                </div>
            </apex:outputPanel>
        </apex:outputPanel>
   </apex:pageBlock>
</apex:form>


********** Apex Class Code************

public class MER_Bulk_Ext {
    //==========================================================
    // Public Fields
    //==========================================================
    public List<ReportItem> reportItemList{get; set;}
    public Boolean isBulkEdit{get; set;}
    public Integer tableHeight {get; set;}
    //==========================================================
    // Private Fields
    //==========================================================
    //Property for Paging
    @TestVisible private ApexPages.StandardSetController stdSetCntrl {get;set;}
    private Integer totalId;
   
    //================================================================
    // Constructor
    //================================================================
    public MER_Bulk_Ext(ApexPages.StandardController controller) {

        List<MER__c> merList = new List<MER__c>();
            merList = [SELECT m.name,
                         m.Status__c,
                         (SELECT i.Column2__c
                            FROM MER_Itemized_Status__r i) itemData
                     FROM MER__c m
                 ORDER BY m.name
                 ];
           
        for(MER__c m: merList){
            ReportItem objItem = new ReportItem();
            objItem.mer = m;
            objItem.itemData = m.MER_Itemized_Status__r;
        }

        this.stdSetCntrl = new ApexPages.StandardSetController(merList);
        this.stdSetCntrl.setPageSize(100);
        this.reportItemList = this.generateMERList();
        this.tableHeight =615;
    }
  
    // Inner Class Definition
    public Class ReportItem {
        public MER__c mer {get; set;}
        public List<MER_Itemized_Status__c> itemData {get; set;}
    }
   
    //---------------------------------------------------------------
    // [save] Button in Page[MER_BulkEdit]
    //---------------------------------------------------------------
    public PageReference saveBulk(){
        List<MER__c> updateMer = new List<MER__c>();
        List<MER_Itemized_Status__c> updateItem = new List<MER_Itemized_Status__c>();
        for (ReportItem mer : this.reportItemList) {
            updateMer.add(mer.mer);
            for(MER_Itemized_Status__c i:mer.mer.MER_Itemized_Status__r){
                updateItem.add(i);
            }
        }
        try {
            if (updateMer.size() > 0) {
                update updateMer;
                ★I can not get the input data from VF. Status__c is not updated.★
            }
            if (updateItem.size() > 0) {
                update updateItem;
            }
        } catch (DMLException e) {
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, e.getDMLMessage(0)));
            return null;
        }
        isBulkEdit=false;
        PageReference pgr = Page.MER_BulkEdit;
        pgr.setRedirect(true);
        return pgr;
    }
   
    //---------------------------------------------------------------
    // [Edit] Button in Page[MER_BulkEdit]
    //---------------------------------------------------------------
    public PageReference editBulk(){
        PageReference pgr = new PageReference('/apex/MER_BulkEdit');
        isBulkEdit=true;
        return pgr;
    }
   
    //---------------------------------------------------------------
    // [Cancel] Button in Page[MER_BulkEdit]
    //---------------------------------------------------------------
    public PageReference cancelBulk(){
        PageReference pgr = new PageReference('/apex/MER_BulkEdit');
        isBulkEdit=false;
        return pgr;
    }
   

   
    //==========================================================
    // Private Method
    //==========================================================
    public List <ReportItem> generateMERList() {
        List<ReportItem> customList = new List<ReportItem>();
       
        for (MER__c mer : (List<MER__c>)this.stdSetCntrl.getRecords()) {
            ReportItem merItem = new ReportItem();
            merItem.mer = mer;
            merItem.itemData = mer.MER_Itemized_Status__r;
            customList.add(merItem);
        }
        return customList;
    }
}
************************************************************************:
Thank you in advance for your help!
I created Apex Batch Class.
When I try to inport over 50,000 rows of CSV file, the following error appears.
"Batchable instance is too big".
I don't know how to resolve this issue...
The following is my batch code.


global with sharing class NSRCOR_MER_Import_Batch implements Database.batchable<string>, Database.Stateful{
    private String m_csvFile;
    private String m_batchLogId;
    Boolean isHeader = true;
    private static Integer rowCount;
    private static Integer importCount =0;
    Boolean success = true;
    String remarks = '';
  
    global NSRCOR_MER_Import_Batch(String csfFile, String batchLogId){
        m_csvFile = csfFile;
        m_batchLogId = batchLogId;
    }
    global Iterable<string> start(Database.batchableContext batchableContext){
       return new NSRCOR_MER_CSVIterator(m_csvFile,'\n');
    }
    global void execute(Database.BatchableContext batchableContext, List<string> scope)  {    
        List<NSRCOR_MER_PO__c> importPO = new List<NSRCOR_MER_PO__c>();
        List<NSRCOR_MER_PO__c> updatePO = new List<NSRCOR_MER_PO__c>();
        Integer lineNo = 0;
        Integer countInsert = 0;
        Integer countUpdate = 0;
        if (rowCount == null){rowCount =0;}
    
        // Get list of exist PO data
        Map<String,NSRCOR_MER_PO__c> poMap = new Map<String,NSRCOR_MER_PO__c>();
        for (NSRCOR_MER_PO__c rt : [SELECT id,name,PO_Title__c, Vendor_Name__c FROM NSRCOR_MER_PO__c]){
            poMap.put(rt.name, rt);
        }
        NSRCOR_MER_Import_Log__c importLog =[SELECT Nubmer_of_Rows__c FROM NSRCOR_MER_Import_Log__c WHERE Id=:m_batchLogId ];
        if(importLog.Nubmer_of_Rows__c ==null){
            rowCount = 0;
        }else{
            rowCount = Integer.valueOf(importLog.Nubmer_of_Rows__c);
        }
      
        Map<Integer,Integer> toInsertRownum = new Map<Integer,Integer>();
        Map<Integer,Integer> toUpdateRownum = new Map<Integer,Integer>();
        Map<Integer,String> poMapInsert= new Map<Integer,String>();
        Map<Integer,String> POMapUpdate= new Map<Integer,String>();
 
        for(String row : scope){
            if(isHeader){
              isHeader = false;
            }else{
              List<String> csvValues = row.split(',');
              String poName = null;
              
                // PO
                NSRCOR_MER_PO__c po     = new NSRCOR_MER_PO__c();
                if(poMap.get(this.deSanitize(csvValues[0].trim()))==null){
                    po.Name             = this.deSanitize(csvValues[0].trim());
                    po.PO_Title__c      = this.deSanitize(csvValues[1].trim());
                    po.Vendor_Name__c   = this.deSanitize(csvValues[2].trim());
                    importPO.add(po);
                    poName = po.Name;
                    poMap.put(poName, po);
                    toInsertRownum.put(countInsert,lineNo);
                    poMapInsert.put(countInsert,poName);
                    countInsert++;
                        
                }else{
                    if(poMap.get(this.deSanitize(csvValues[0].trim())).PO_Title__c != this.deSanitize(csvValues[1].trim()) ||
                       poMap.get(this.deSanitize(csvValues[0].trim())).Vendor_Name__c != this.deSanitize(csvValues[2].trim())){
                        poMap.get(this.deSanitize(csvValues[0].trim())).PO_Title__c    = this.deSanitize(csvValues[1].trim());
                        poMap.get(this.deSanitize(csvValues[0].trim())).Vendor_Name__c = this.deSanitize(csvValues[2].trim());
                        updatePO.add(poMap.get(this.deSanitize(csvValues[0].trim())));
                        toUpdateRownum.put(countUpdate,lineNo);
                        poMapUpdate.put(countUpdate,poName);
                        countUpdate++;
                    }
                }
                lineNo++;
              
            }
         
        }
      
        if(importPO!=null && importPO.size()>0){
            //insert importPO;
            Database.SaveResult[] srList = Database.insert(importPO, false);
            Integer ln = 0;
            for (Database.SaveResult sr : srList) {
                if (sr.isSuccess()) {
                    //importCount ++;             
                }else{
                    success = false;
                    // Operation failed, so get all errors              
                    for(Database.Error e : sr.getErrors()) {
                        Integer num = toInsertRownum.get(ln) + rowCount + 1;
                        //remarks = remarks + 'ERROR: Row '+ num + '; '+ 'PO No. '+  poMapInsert.get(ln)+'; '+e.getMessage()+'\n';
                        remarks = remarks + 'ERROR: Row '+ num +'; '+e.getMessage()+'\n';
                    }
                }
                ln++;
            }       
          
        }
        if(updatePO!=null && updatePO.size()>0){
           // update updatePO;
            Database.SaveResult[] srList = Database.update(updatePO, false);
            Integer ln = 0;
            for (Database.SaveResult sr : srList) {
                if (sr.isSuccess()) {
                    //importCount ++;             
                }else{
                    success = false;
                    // Operation failed, so get all errors              
                    for(Database.Error e : sr.getErrors()) {
                        Integer num = toUpdateRownum.get(ln) + rowCount + 1;
                        //remarks = remarks + 'ERROR: Row '+ num + '; '+ 'PO No. '+  poMapUpdate.get(ln)+'; '+e.getMessage()+'\n';
                        remarks = remarks + 'ERROR: Row '+ num +'; '+e.getMessage()+'\n';
                    }
                }
                ln++;
            }
        }
      
        rowCount =  rowCount + lineNo;         
        importLog.Nubmer_of_Rows__c =  rowCount;
        update importLog;

    }
    global void finish(Database.BatchableContext batchableContext){
      
      
        NSRCOR_MER_Import_Log__c importLog = [SELECT Id,Name,Status__c,Remarks__c,Import_Count__c, Nubmer_of_Rows__c FROM NSRCOR_MER_Import_Log__c WHERE Id=:m_batchLogId];
        if(!success){
            if(remarks.length() > 2000){
                importLog.Remarks__c = remarks.substring(0,2000);
            }else{
                importLog.Remarks__c = remarks;
            }
            importLog.Status__c = 'Failed';
          
        }
        //importLog.Import_Count__c = String.valueOf(importCount);
        importLog.Nubmer_of_Rows__c =0;
        Update importLog;
      
        Database.executeBatch(new NSRCOR_MER_Items_Import_Batch(m_csvFile, m_batchLogId));
      
    }
  
    private String deSanitize(String value) {
        return value.replace('#comma#',',').replace('#dbc#','"');
    }
}