+ Start a Discussion
prabhat jhaprabhat jha 

testclass failing when testing with@seealldata=false but passes when set to true.Error(System.DmlException: Insert failed. First exception on row 0; first error: STANDARD_PRICE_NOT_DEFINED, No standard price defined for this product: [])

i am inserting Standard price book entry as well as Custom Price book entry for new Products (identified by Futurecodeset which contains productcodes for new Product)in my Batch apex  to call Method 1)insertSTDPBEntry(futurePCodeSet);and 2)insertCUSTOMPBEntry(futurePCodeSet);
//batch class
global class ProductBatchInsert implements Database.batchable<sobject>{
    global Map<String, Product2> pCodeToPMap = new Map<String, Product2>();
    global Map<String, Product2> existingProductCodeMap = new Map<String, Product2>(); // existing products from product codes uploaded by  file
    global List<Product2> newPList; // product list from csv for update (New)
    global List<Product2> oldPList; // product list from salesforce for update (Old)
    global List<Product2> insertPList; // product list to insert
    global List<Product2> insertPcloudList;//clouds products to be inserted
    global Set<String> futurePCodeSet; 
    global static Decimal exchangeRateUSDTOEUR = 0.0;
    global static Decimal exchangeRateUSDTOGBP = 0.0;
    global static Decimal exchangeRateUSDTOAED = 0.0;
    
    
    
    
    global ProductBatchInsert(){}
    
    global Database.QueryLocator start(Database.BatchableContext BC) {
        // collect the batches of records or objects to be passed to execute
         
        String query = 'SELECT ID,Item_Category_ID__c,Contract_Price__c,DiscountCategory__c,Brand__c,Item_Category_Name__c,Manufacturer_Part_Number__c,Manufacturer__c,MSRP__c,Name,Part_Description__c,Sender_ID__c,Technology__c,Vendor_Part_Number__c FROM Oracle201815__c';
        return Database.getQueryLocator(query);
    }
    global void execute(Database.BatchableContext batchableContext, List<Oracle201815__c> scope){ 
        Product2 p2Obj = new Product2();
        for(Oracle201815__c ProductFileIndividualRec : scope){
            if(ProductFileIndividualRec.Manufacturer_Part_Number__c!=null){
            	List<String> customFieldset = new List<String>();
                p2Obj = new Product2();
                p2Obj.isActive = true; 
                p2Obj.ProductCode = ProductFileIndividualRec.Manufacturer_Part_Number__c;
                p2Obj.Name = ProductFileIndividualRec.Part_Description__c;
                p2Obj.Category__c=ProductFileIndividualRec.Item_Category_Name__c;               
                p2Obj.Description=ProductFileIndividualRec.Part_Description__c;               
                p2Obj.List_Price__c=ProductFileIndividualRec.MSRP__c;               
                p2Obj.Product_Manufacturer__c=ProductFileIndividualRec.Manufacturer__c;
              
               	customFieldset = CintraUtil.DecideCustomFields(ProductFileIndividualRec.Part_Description__c,ProductFileIndividualRec.Item_Category_Name__c);//method to determine the cintra category and Revenue type and skip the cloud realted products
                    if(customFieldset!=null && customFieldset.size()>0){
                    	 System.debug('customFieldsetnotnull'+customFieldset); 
                        p2Obj.Cintra_Category__c=customFieldset.get(1);
                        System.debug('CintraCategoryDecisionResult'+customFieldset.get(1));
                        p2Obj.Family=customFieldset.get(0);
                        System.debug('CintrafamilyDecisionResult'+customFieldset.get(0));
                        p2Obj.Product_Family_Group__c = 'Resell';
                     }
                     else{
                     	 System.debug('customFieldsetnull');
                     	p2Obj.Cintra_Category__c='NA';
                        p2Obj.Family='NA';
                        p2Obj.Product_Family_Group__c='NA';
                     }
                //System.debug('customFieldsetvalues'+customFieldset);
                pCodeToPMap.put(ProductFileIndividualRec.Manufacturer_Part_Number__c,p2Obj);
                
                
    			}
				}
        
        System.debug('pCodeToPMaplist'+pCodeToPMap.size());
        if(pCodeToPMap != null && pCodeToPMap.size() > 0){
            System.debug('before insertingexistingproductmap00001'+pCodeToPMap.keyset());
            //List<String> pCodeSet =new List<String>(pCodeToPMap.keyset());
            //System.debug('listofproductcodes***'+pCodeSet);
            /*for(String st : pCodeToPMap.keyset() ){
               pCodeSet.add('\'+st+'"') ;
            }*/
         for(PricebookEntry  pricebookEntryObj : [SELECT Product2Id,Product2.ChangeLog__c,Product2.IsActive,Product2.ProductCode,Product2.Name,Product2.Category__c,Product2.Description,Product2.List_Price__c,Product2.Product_Manufacturer__c,Product2.Revenue_Type__c,Product2.Artesian_Comment__c,Product2.Cintra_Category__c,Product2.Family,Product2.Product_Family_Group__c FROM PricebookEntry WHERE ((Product2.ProductCode IN : pCodeToPMap.keyset()) and (CurrencyIsoCode ='USD') and (Pricebook2.name = 'Cintra Master Pricebook 2017 - 2018'))]){
               System.debug('before insertingexistingproductmap0000');
             if(pricebookEntryObj.Product2.ProductCode != null){
                    System.debug('before insertingexistingproductmap0');
                    Product2 pObj1 = new product2();
                        pObj1.Id=pricebookEntryObj.Product2Id;
                           pObj1.IsActive=pricebookEntryObj.Product2.IsActive; 
                           pObj1.ProductCode=pricebookEntryObj.Product2.ProductCode;
                           pObj1.Name=pricebookEntryObj.Product2.Name;
                           pObj1.Category__c=pricebookEntryObj.Product2.Category__c;
                           pObj1.Description=pricebookEntryObj.Product2.Description;
                           pObj1.List_Price__c=pricebookEntryObj.Product2.List_Price__c;
                           pObj1.Product_Manufacturer__c=pricebookEntryObj.Product2.Product_Manufacturer__c;
                 		   pObj1.ChangeLog__c=pricebookEntryObj.Product2.ChangeLog__c;
                          // pObj1.Revenue_Type__c=pricebookEntryObj.Product2.Revenue_Type__c;
                           pObj1.Artesian_Comment__c=pricebookEntryObj.Product2.Artesian_Comment__c;
                           pObj1.Cintra_Category__c=pricebookEntryObj.Product2.Cintra_Category__c;
                           pObj1.Family=pricebookEntryObj.Product2.Family;
                           pObj1.Product_Family_Group__c =pricebookEntryObj.Product2.Product_Family_Group__c;
             		System.debug('before insertingexistingproductmap1');
                    existingProductCodeMap.put(pricebookEntryObj.Product2.ProductCode, pObj1);
                    System.debug('before insertingexistingproductmap2');
                    System.debug('existingProductCodeMap'+existingProductCodeMap.values());
               	 }    
            }
            newPList = new List<Product2>();
            oldPList = new List<Product2>();
            insertPList = new List<Product2>();//contains new Product List for insert
            insertPcloudList = new List<Product2>();//contains new cloudProduct List for insert
            futurePCodeSet = new Set<String>();
            
           for(String Pcode : pCodeToPMap.keySet()){
               System.debug('pCodeToPMapsizecheck'+pCodeToPMap.size());
                if(existingProductCodeMap.keySet().contains(PCode)){
                    oldPList.add(existingProductCodeMap.get(PCode));
                    newPList.add(pCodeToPMap.get(PCode));
                    //System.debug('newProductList'+newPList);
                     System.debug('oldPList****'+oldPList);
                     System.debug('newPList******'+newPList);
                    
                }else{
                    if(pCodeToPMap.get(PCode).Family!='NA'){//excluding products whose product family is NA means non cloud products
                    insertPList.add(pCodeToPMap.get(PCode));
                    System.debug('insertproductlist****()'+insertPList);
                     futurePCodeSet.add(PCode);
                      System.debug('futurePCodeSet****()'+futurePCodeSet);
                    }//product codes to create StdPBEntry and CustomPBEntry
                    else{
                    	insertPcloudList.add(pCodeToPMap.get(PCode));
                    	//System.debug('cloudlistsize****'+insertPcloudList.size());
                    }
                    
                }
                
                
            }for(Product2 pcloud:insertPcloudList){
            	System.debug('cloudlistsize****'+pcloud.ProductCode);
            }
            //System.debug('cloudlistsize****'+insertPcloudList);
            System.debug('new products in file******'+insertPList);
            
            if(insertPList != null && insertPList.size() > 0){
                System.debug('insertplistsize****'+insertPList.size());
                insert insertPList;
                insertPList.clear();
                insertSTDPBEntry(futurePCodeSet);
                insertCUSTOMPBEntry(futurePCodeSet);
                
            }
            if(oldPList != null && oldPList.size() > 0){
                System.debug('productswithchangesize****'+oldPList.size());
                System.debug('productswithchange****'+oldPList);
                compareAndUpdateProducts();
            }
   	 	}
    }
    
           

        
    
    global void finish(Database.BatchableContext BC){
            // Add batch job calling logic in Finish method
		   // ProductInactivationBatchClass b = new ProductInactivationBatchClass(); 
			//database.executebatch(b);
  }
     public static void insertSTDPBEntry(Set<String> futurePCodeSet){
        String pricebookId = null;
        if(futurePCodeSet!= null && futurePCodeSet.size()>0){
            List<Pricebook2> pbList = [select Id, Name, IsActive from PriceBook2 where IsStandard=True LIMIT 1]; 
            if(pbList != null && pbList.size()>0){
                pricebookId = pbList[0].Id;
            }
            if(pricebookId != null){
                PricebookEntry pbeObj;
                List<PricebookEntry> pbeList = new List<PricebookEntry>();
                exchangeRateUSDTOEUR = 0.0;
                  exchangeRateUSDTOGBP = 0.0;
                  exchangeRateUSDTOAED = 0.0;
                
                try{
                    CintraOtherSettingsCS__c cosObj = CintraOtherSettingsCS__c.getValues('Oracle_Exchange_Rate_USD_TO_EUR');
                    exchangeRateUSDTOEUR = Decimal.valueOf(cosObj.value__c);
                    System.debug('exchangeRateUSDTOEUR***'+exchangeRateUSDTOEUR);
                    CintraOtherSettingsCS__c cosObj1 = CintraOtherSettingsCS__c.getValues('Oracle_Exchange_Rate_USD_TO_GBP');
                    exchangeRateUSDTOGBP = Decimal.valueOf(cosObj1.value__c);
                    System.debug('exchangeRateUSDTOGBP***'+exchangeRateUSDTOGBP);
                    CintraOtherSettingsCS__c cosObj2 = CintraOtherSettingsCS__c.getValues('Oracle_Exchange_Rate_USD_TO_AED');
                    exchangeRateUSDTOAED = Decimal.valueOf(cosObj2.value__c);
                }catch(Exception e){
                  exchangeRateUSDTOEUR = 0.8;
                  exchangeRateUSDTOGBP = 0.8;
                  exchangeRateUSDTOAED = 0.8;
                }
                for(Product2 pObj : [SELECT Id, ProductCode, List_Price__c, CurrencyIsoCode FROM Product2 WHERE ProductCode IN : futurePCodeSet]){
                    pbeObj = new PriceBookEntry();
                    pbeObj.Product2ID = pObj.Id;
                    pbeObj.PriceBook2ID = pricebookId;
                    pbeObj.CurrencyIsoCode = pObj.CurrencyIsoCode;
                    pbeObj.UnitPrice = (pObj.List_Price__c != null) ? pObj.List_Price__c : 0.0;
                    pbeObj.IsActive = true;
                    pbeList.add(pbeObj);
                    
                    pbeObj = new PriceBookEntry();
                    pbeObj.Product2ID = pObj.Id;
                    pbeObj.PriceBook2ID = pricebookId;
                    pbeObj.CurrencyIsoCode = 'GBP';
                    pbeObj.UnitPrice = (pObj.List_Price__c != null) ? (pObj.List_Price__c * exchangeRateUSDTOGBP) : 0.0;
                    pbeObj.IsActive = true;
                    pbeList.add(pbeObj);
                    
                    pbeObj = new PriceBookEntry();
                    pbeObj.Product2ID = pObj.Id;
                    pbeObj.PriceBook2ID = pricebookId;
                    pbeObj.CurrencyIsoCode = 'EUR';
                    pbeObj.UnitPrice = (pObj.List_Price__c != null) ? (pObj.List_Price__c * exchangeRateUSDTOEUR) : 0.0;
                    pbeObj.IsActive = true;
                    pbeList.add(pbeObj);
                    
                    pbeObj = new PriceBookEntry();
                    pbeObj.Product2ID = pObj.Id;
                    pbeObj.PriceBook2ID = pricebookId;
                    pbeObj.CurrencyIsoCode = 'AED';
                    pbeObj.UnitPrice = (pObj.List_Price__c != null) ? (pObj.List_Price__c * exchangeRateUSDTOAED) : 0.0;
                    pbeObj.IsActive = true;
                    pbeList.add(pbeObj);
                }
                if(pbeList != null && pbeList.size() > 0){
                    insert pbeList;
                }
            }
        }
    }
    
    public static void insertCUSTOMPBEntry(Set<String> futurePCodeSet){
        String pricebookId = null;
        //pricebookId = Label.Active_Pricebook;//create one custom label which contains the id for Custom Pricebook
        if(futurePCodeSet!= null && futurePCodeSet.size()>0){
            List<Pricebook2> pbList = [select Id, Name, IsActive from PriceBook2 where NAME ='Cintra Master Pricebook 2017 - 2018']; 
            if(pbList != null && pbList.size()>0){
                pricebookId = pbList[0].Id;
            }
            if(pricebookId != null){
                PricebookEntry pbeObj;
                List<PricebookEntry> pbeList = new List<PricebookEntry>();
                exchangeRateUSDTOEUR = 0.0;
                  exchangeRateUSDTOGBP = 0.0;
                  exchangeRateUSDTOAED = 0.0;
                
                try{
                    CintraOtherSettingsCS__c cosObj = CintraOtherSettingsCS__c.getValues('Oracle_Exchange_Rate_USD_TO_EUR');
                    exchangeRateUSDTOEUR = Decimal.valueOf(cosObj.value__c);
                    system.debug('checkingcustomsettingvalues1'+exchangeRateUSDTOEUR);
                    CintraOtherSettingsCS__c cosObj1 = CintraOtherSettingsCS__c.getValues('Oracle_Exchange_Rate_USD_TO_GBP');
                    exchangeRateUSDTOGBP = Decimal.valueOf(cosObj1.value__c);
                    system.debug('checkingcustomsettingvalues2'+exchangeRateUSDTOGBP);
                    CintraOtherSettingsCS__c cosObj2 = CintraOtherSettingsCS__c.getValues('Oracle_Exchange_Rate_USD_TO_AED');
                    exchangeRateUSDTOAED = Decimal.valueOf(cosObj2.value__c);
                }catch(Exception e){
                  
                 	 exchangeRateUSDTOGBP = 0.8;
                     exchangeRateUSDTOEUR = 0.8;
                  	exchangeRateUSDTOAED = 0.8;
                }
                for(Product2 pObj : [SELECT Id, ProductCode, List_Price__c, CurrencyIsoCode FROM Product2 WHERE ProductCode IN : futurePCodeSet]){
                    pbeObj = new PriceBookEntry();
                    pbeObj.Product2ID = pObj.Id;
                    pbeObj.PriceBook2ID = pricebookId;
                    pbeObj.CurrencyIsoCode = pObj.CurrencyIsoCode;
                    pbeObj.UnitPrice = (pObj.List_Price__c != null) ? pObj.List_Price__c : 0.0;
                    pbeObj.IsActive = true;
                    pbeList.add(pbeObj);
                    
                    pbeObj = new PriceBookEntry();
                    pbeObj.Product2ID = pObj.Id;
                    pbeObj.PriceBook2ID = pricebookId;
                    pbeObj.CurrencyIsoCode = 'GBP';
                    pbeObj.UnitPrice = (pObj.List_Price__c != null) ? (pObj.List_Price__c * exchangeRateUSDTOGBP) : 0.0;
                    pbeObj.IsActive = true;
                    pbeList.add(pbeObj);
                    
                    pbeObj = new PriceBookEntry();
                    pbeObj.Product2ID = pObj.Id;
                    pbeObj.PriceBook2ID = pricebookId;
                    pbeObj.CurrencyIsoCode = 'EUR';
                    pbeObj.UnitPrice = (pObj.List_Price__c != null) ? (pObj.List_Price__c * exchangeRateUSDTOEUR) : 0.0;
                    pbeObj.IsActive = true;
                    pbeList.add(pbeObj);
                    
                    pbeObj = new PriceBookEntry();
                    pbeObj.Product2ID = pObj.Id;
                    pbeObj.PriceBook2ID = pricebookId;
                    pbeObj.CurrencyIsoCode = 'AED';
                    pbeObj.UnitPrice = (pObj.List_Price__c != null) ? (pObj.List_Price__c * exchangeRateUSDTOAED) : 0.0;
                    pbeObj.IsActive = true;
                    pbeList.add(pbeObj);
                }
                if(pbeList != null && pbeList.size() > 0){
                    insert pbeList;
                }
            }
        }
    }
      private void compareAndUpdateProducts(){
        exchangeRateUSDTOEUR = 0.0;
        exchangeRateUSDTOGBP = 0.0;
        exchangeRateUSDTOAED = 0.0;
        try{
            /*if(test.isRunningTest()){
                exchangeRateUSDTOGBP = 0.8;
                exchangeRateUSDTOEUR = 0.8;
                exchangeRateUSDTOAED = 0.8;}*/
        	CintraOtherSettingsCS__c cosObj = CintraOtherSettingsCS__c.getValues('Oracle_Exchange_Rate_USD_TO_EUR');
            exchangeRateUSDTOEUR = Decimal.valueOf(cosObj.value__c);
            system.debug('checkingcustomsettingvalues1'+exchangeRateUSDTOEUR);
            CintraOtherSettingsCS__c cosObj1 = CintraOtherSettingsCS__c.getValues('Oracle_Exchange_Rate_USD_TO_GBP');
            exchangeRateUSDTOGBP = Decimal.valueOf(cosObj1.value__c);
            system.debug('checkingcustomsettingvalues2'+exchangeRateUSDTOGBP);
            CintraOtherSettingsCS__c cosObj2 = CintraOtherSettingsCS__c.getValues('Oracle_Exchange_Rate_USD_TO_AED');
            exchangeRateUSDTOAED = Decimal.valueOf(cosObj2.value__c);
             
        }
        catch(Exception e){
     	 exchangeRateUSDTOGBP = 0.8;
         exchangeRateUSDTOEUR = 0.8;
      	exchangeRateUSDTOAED = 0.8;
        }
        List<Product2> updatePList = new List<Product2>();
        Map<Id, Decimal> pIdToPriceMap = new Map<Id, Decimal>();
        List<PricebookEntry> pCodeToPMap = new List<PricebookEntry>();
        Boolean isUpdate;
        Boolean isPricebookUpdate;
         
        for(Integer i=0; i<oldPList.size(); i++){
            isUpdate = false;
            isPricebookUpdate = false;
            String Changelog=(oldPList[i].ChangeLog__c!=null)?oldPList[i].ChangeLog__c:'';
           
            if(newPList[i].isActive != oldPList[i].isActive){
                Changelog+='Product'+oldPList[i].ProductCode+'changed from'+oldPList[i].isActive+'to'+newPList[i].isActive+'\r\n';
                oldPList[i].isActive = newPList[i].isActive;
                isUpdate = true;
                
            }
            if(newPList[i].Name != null && newPList[i].Name != oldPList[i].Name){
                Changelog+='Product'+oldPList[i].ProductCode+'Name changed from'+oldPList[i].Name+'to'+newPList[i].Name+'\r\n';
                oldPList[i].Name = newPList[i].Name;
                isUpdate = true;
                
            }
            if(newPList[i].List_Price__c != null && newPList[i].List_Price__c != oldPList[i].List_Price__c){
                Changelog+='Product'+oldPList[i].ProductCode+'List price changed from'+oldPList[i].List_Price__c+'to'+newPList[i].List_Price__c+'\r\n';
                oldPList[i].List_Price__c = newPList[i].List_Price__c;
                isUpdate = true;
                isPricebookUpdate = true;
            }
            if(newPList[i].Family != null && newPList[i].Family != oldPList[i].Family){
                 Changelog+='Product'+oldPList[i].ProductCode+'Family changed from'+oldPList[i].Family+'to'+newPList[i].Family+'\r\n';
                oldPList[i].Family = newPList[i].Family;
                isUpdate = true;
            }
            if(newPList[i].Description != null && newPList[i].Description != oldPList[i].Description){
                 Changelog+='Product'+oldPList[i].ProductCode+'Description changed from'+oldPList[i].Description+'to'+newPList[i].Description+'\r\n';
                oldPList[i].Description = newPList[i].Description;
                isUpdate = true;
            }
           if(newPList[i].Category__c !=null && newPList[i].Category__c != oldPList[i].Category__c ) {
               if( !(newPList[i].Category__c).containsIgnoreCase('cloud')){
                    Changelog+='Product'+oldPList[i].ProductCode+'Category changed from'+oldPList[i].Category__c+'to'+newPList[i].Category__c+'\r\n';
                oldPList[i].Category__c = newPList[i].Category__c;
                oldPList[i].Cintra_Category__c=newPList[i].Cintra_Category__c;
               oldPList[i].Family=newPList[i].Family;
                isUpdate = true;
                   }
            }
            if(isUpdate){
                //Changelog+='on'+System.now();
                oldPlist[i].ChangeLog__c='['+System.now()+']'+'--'+Changelog;
                updatePList.add(oldPList[i]);
                System.debug('updatePlist***'+updatePList);
            }
            if(isPricebookUpdate){
                pIdToPriceMap.put(oldPList[i].Id, newPList[i].List_Price__c);
            }
        }
        if(updatePList != null && updatePList.size() > 0){
            update updatePList;
        }
        List<PricebookEntry> updatePBEList = new List<PricebookEntry>();
        for(PricebookEntry pbeObj : [SELECT Id, UnitPrice, CurrencyIsoCode, Product2Id FROM PricebookEntry WHERE Product2Id IN : pIdToPriceMap.keySet()]){
            if(pbeObj.CurrencyIsoCode == 'USD'){
                pbeObj.UnitPrice = pIdToPriceMap.get(pbeObj.Product2Id);
            }else if(pbeObj.CurrencyIsoCode == 'GBP'){
                pbeObj.UnitPrice = pIdToPriceMap.get(pbeObj.Product2Id) * exchangeRateUSDTOGBP;
            }else if(pbeObj.CurrencyIsoCode == 'AED'){
                pbeObj.UnitPrice = pIdToPriceMap.get(pbeObj.Product2Id) * exchangeRateUSDTOAED;
            }else if(pbeObj.CurrencyIsoCode == 'EUR'){
                pbeObj.UnitPrice = pIdToPriceMap.get(pbeObj.Product2Id) * exchangeRateUSDTOEUR;
            }
            updatePBEList.add(pbeObj);
        }
        if(updatePBEList != null && updatePBEList.size() > 0){
            update updatePBEList;
        }
    }
    
   
  
    
    
}
//test class for Batch class
@isTest
public class ProductBatchInserttest 
{
   @isTest(seeAllData=false)
    static  void testMethod1() 
    {
        List<Oracle201815__c> lstOraclefile= new List<Oracle201815__c>();
       // List<Product2> prdObj = new List<Product2>();
      /*  List<PricebookEntry> pbeList = new List<PricebookEntry>();
       CintraOtherSettingsCS__c cosObj = new CintraOtherSettingsCS__c(Name='Oracle_Exchange_Rate_USD_TO_EUR', Value__c = '1');
      insert cosObj;
        CintraOtherSettingsCS__c cosObj1 = new CintraOtherSettingsCS__c(Name='Oracle_Exchange_Rate_USD_TO_GBP', Value__c = '0.8');
      insert cosObj1;
        CintraOtherSettingsCS__c cosObj2 = new CintraOtherSettingsCS__c(Name='Oracle_Exchange_Rate_USD_TO_AED', Value__c = '0.6');
      insert cosObj2;*/
      
        Product2 pObj = new Product2 (Name='Test Product Entry 1',Description='Test Product Entry 1',productCode = 'Name10', isActive = true);
       insert(pObj);
        //standard PBEntry
       Id pricebookId = Test.getStandardPricebookId(); 
        PricebookEntry standardPrice = new PricebookEntry(
            Pricebook2Id = pricebookId, Product2Id = pObj.Id,CurrencyIsoCode = 'USD',
            UnitPrice = 10000, IsActive = true);
        insert standardPrice;
        PricebookEntry standardPrice1 = new PricebookEntry(
            Pricebook2Id = pricebookId, Product2Id = pObj.Id,CurrencyIsoCode = 'GBP',
            UnitPrice = 10000, IsActive = true);
        insert standardPrice1;
        PricebookEntry standardPrice2 = new PricebookEntry(
            Pricebook2Id = pricebookId, Product2Id = pObj.Id,CurrencyIsoCode = 'AED',
            UnitPrice = 10000, IsActive = true);
        insert standardPrice2;
        PricebookEntry standardPrice3 = new PricebookEntry(
            Pricebook2Id = pricebookId, Product2Id = pObj.Id,CurrencyIsoCode = 'EUR',
            UnitPrice = 10000, IsActive = true);
        insert standardPrice3;
   
      
        //CustomPBentry
        Pricebook2 customPB = new Pricebook2(Name='Cintra Master Pricebook 2017 - 2018', isActive=true);
        insert customPB;
        
        // 2. Insert a price book entry with a custom price.
       	 PricebookEntry customPBEUSD = new PricebookEntry(Pricebook2Id = customPB.Id, Product2Id = pObj.Id,UnitPrice = 12000,CurrencyIsoCode = 'USD', IsActive = true);
        insert customPBEUSD;
        PricebookEntry customPBEGBP = new PricebookEntry(Pricebook2Id = customPB.Id, Product2Id = pObj.Id,UnitPrice = 12000,CurrencyIsoCode = 'GBP', IsActive = true);
        insert customPBEGBP;
        PricebookEntry customPBEEUR = new PricebookEntry(Pricebook2Id = customPB.Id, Product2Id = pObj.Id,UnitPrice = 12000,CurrencyIsoCode = 'EUR', IsActive = true);
        insert customPBEEUR;
        PricebookEntry customPBEAED = new PricebookEntry(Pricebook2Id = customPB.Id, Product2Id = pObj.Id,UnitPrice = 12000,CurrencyIsoCode = 'AED', IsActive = true);
        insert customPBEAED;
        
        
        
        
        
        for(Integer i=0 ;i <100;i++)//for non cloud Products
        {
            Oracle201815__c oracleRec = new Oracle201815__c();
           
              	oracleRec.Manufacturer_Part_Number__c='CODE'+i;
                oracleRec.Part_Description__c='Name'+i;
                oracleRec.Item_Category_Name__c='HW'+i;               
                oracleRec.Part_Description__c='Name'+i;               
             	oracleRec.MSRP__c=i;              
                oracleRec.Manufacturer__c='oracle';
            lstOraclefile.add(oracleRec);
        }
        for(Integer i=0 ;i <100;i++)//for cloud products
        {
            Oracle201815__c oracleRec = new Oracle201815__c();
           
              oracleRec.Manufacturer_Part_Number__c='Name1'+i;
                oracleRec.Part_Description__c='Name1'+i;
                oracleRec.Item_Category_Name__c='Cloud'+i;               
                oracleRec.Part_Description__c='Name1'+i;               
              oracleRec.MSRP__c=i;              
                oracleRec.Manufacturer__c='oracle';
            lstOraclefile.add(oracleRec);
        }
        Oracle201815__c oracleRec = new Oracle201815__c();
           
              	oracleRec.Manufacturer_Part_Number__c = 'PROD1000';
                oracleRec.Part_Description__c='Name1';
                oracleRec.Item_Category_Name__c='SW';               
                oracleRec.Part_Description__c='Name1';               
              	oracleRec.MSRP__c=100;              
                oracleRec.Manufacturer__c='oracle';
        		
        
            lstOraclefile.add(oracleRec);
        
        insert lstOraclefile;
        
        Test.startTest();

            ProductBatchInsert obj = new ProductBatchInsert();
           ID BatchId =DataBase.executeBatch(obj,2000); 
        //System.abortJob(batchID);
            
        Test.stopTest();
    }
}

 
GauravGargGauravGarg
Prabhat,

Please use this approach to get Standard price book
 
private static Pricebook2 stdPriceBook;  // Singleton, remember when first referenced

//  ------------------------------------------------------
//  getStdPricebookId : as of V31, testmethods can locate std pricebook wo seeAlldata=true
//  ------------------------------------------------------
public static ID getStdPricebookId() {
    if (Test.isRunningTest())   return Test.getStandardPricebookId();
    return getStdPricebook().id;    
} 

//  -------------------------------------------------------
//  getStdPriceBook: Singleton
//  -------------------------------------------------------
public static Pricebook2    getStdPriceBook () {
    if (stdPriceBook == null) 
        stdPriceBook    = [select id, name from Pricebook2 where isStandard = true limit 1];
    return stdPriceBook;


It's a utility class to get Standard Price book, incase system standard pricebook is not defined. 

Thanks,

Gaurav
Skype: gaurav62990