Skip to main content
added 92 characters in body
Source Link
sfdc
  • 13.8k
  • 19
  • 136
  • 218

Here is the debug log of those two lines enter image description here..I see the order item is being picked but not sure how to check for active pricebookentry

enter image description here How should I assign product to OrderItem ?

Here is the debug log of those two lines enter image description here How should I assign product to OrderItem ?

Here is the debug log of those two lines..I see the order item is being picked but not sure how to check for active pricebookentry

enter image description here How should I assign product to OrderItem ?

added 125 characters in body
Source Link
sfdc
  • 13.8k
  • 19
  • 136
  • 218

HowHere is the debug log of those two lines enter image description here How should I assign product to OrderItem ?

How should I assign product to OrderItem ?

Here is the debug log of those two lines enter image description here How should I assign product to OrderItem ?

added 2951 characters in body
Source Link
sfdc
  • 13.8k
  • 19
  • 136
  • 218
public class ReductionOrderProductsExtensions {
  
    public PageReferenceList<OrderItem> saveorderItems{get;set;}
    public List<OrderItem> orderItems2{get;set;}
    public String oId;
    public List<OrderItemWrapper> orderItemList{get;set;}
    public List<Id> oiIds = new List<Id>();
    public List<OrderItem> selectedOItems = new list<OrderItem>();
    public List<OrderItem> oItemsToInsert = new list<OrderItem>();
    
    public ReductionOrderProductsExtensions(ApexPages.StandardController controller) {
          oId = ApexPages.currentPage().getParameters().get('OrderId');
          this.orderItemList  = new List<OrderItemWrapper>();  
         try getOrderItemSet();  
      }
    
    public void getOrderItemSet()
     {        
         Order o = [select AccountId,Id from Order selectedOItemswhere Id = :oId];
         orderItems = [select orderId,Order.clearAccountId,Status__c,quantity,Product_Family__c,installed_billable_as_of__c,Vendor__c,Circuit_type__c,Circuit_Speed__c,Pricebookentry.Product2.Name,ListPrice,UnitPrice,Vendor_Changed__c,Installed_Quantity__c,Revenue_Type__c,Order.Status from OrderItem 
                            where Order.AccountId =: o.AccountId and Order.Status  = 'Activated' and quantity >0];
         set<String> uniqueOItems = new set<String>();
         
         for(OrderItemWrapperOrderItem owrapperoi:orderItems){
             if(!uniqueOItems.contains(oi.Pricebookentry.Product2.Name + oi.Vendor__c + oi.Circuit_Speed__c + oi.Circuit_Type__c)){  
                 uniqueOItems.add(oi.Pricebookentry.Product2.Name + oi.Vendor__c + oi.Circuit_Speed__c + oi.Circuit_Type__c);
                  oiIds.add(oi.Id);
              }
           }   
         orderItems2 = [select orderId,Order.AccountId,Status__c,quantity,Product_Family__c,installed_billable_as_of__c,Vendor__c,Circuit_type__c,Circuit_Speed__c,PricebookEntry.Product2Id,Pricebookentry.Product2.Name,ListPrice,UnitPrice,Vendor_Changed__c,Installed_Quantity__c,Revenue_Type__c,Order.Status,Id from OrderItem 
                            where Id in: oiIds];
         for(OrderItem oi:orderItems2){
          this.orderItemList.add(new OrderItemWrapper(oi));
         }
     }
    
    public class OrderItemWrapper{
  
        public OrderItem oitem{get;set;}
  
    if    public Boolean selected{get;set;}
 
        public OrderItemWrapper(owrapperOrderItem o){
            this.oitem = o;
            this.selected === truefalse;
        }
 
    }
    
    public PageReference save(){
     
     try{
          selectedOItems.clear();
         for(OrderItemWrapper owrapper : orderItemList){
            if(owrapper.selected == true)
             selectedOItems.add(owrapper.oitem);
           }
    }
    system.debug('selectedOItems ###'+selectedOItems);
         for(OrderItem oi:selectedOItems){
             system.debug('oi ###'+oi);
            OrderItem o = new OrderItem();
             system.debug('o ###'+o);
             system.debug('oi.PricebookEntry.Product2Id ###'+ oi.PricebookEntry.Product2Id);
             system.debug('o.PricebookEntry.Product2Id ###'+ o.PricebookEntry.Product2Id);     
             
 o.PricebookEntry.Product2Id = oi.PricebookEntry.Product2Id;//Error 
 on this line
          system.debug('oi.PricebookEntry.Product2Id ###'+ oi.PricebookEntry.Product2Id);
            o.Quantity = oi.Quantity;
                o.unitPrice = oi.UnitPrice;
                 system.debug('oId ###'+oId);
                o.orderId = oId; 
                oItemsToInsert.add(o); 
           }
   }
       system.debug('oItemsToInsert ###'+oItemsToInsert);
       
      
         if(oItemsToInsert.size()>0)
                insert oItemsToInsert;
             
               pageReference ref = ApexPages.currentPage(); 
               Id id = ref.getParameters().get('OrderId');
               ref.getParameters().clear();
               ref.getParameters().put('OrderId', id);  
               ref.setRedirect(true);
               return ref;
            
         }
         
         catch(Exception ex){
          
           ApexPages.addMessages(ex);
      
     }
      
    } return null;
     
    }
    
    public PageReference cancel(){
     return null;
      return new PageReference('/' + oId);
    
    }
     
}
    public PageReference save(){
         
         try{
              selectedOItems.clear();
             for(OrderItemWrapper owrapper : orderItemList){
                if(owrapper.selected == true)
                 selectedOItems.add(owrapper.oitem);
               }
             for(OrderItem oi:selectedOItems){
                OrderItem o = new OrderItem();
 system.debug('oi.PricebookEntry.Product2Id ###'+ oi.PricebookEntry.Product2Id);
             system.debug('o.PricebookEntry.Product2Id ###'+ o.PricebookEntry.Product2Id);                 
 o.PricebookEntry.Product2Id = oi.PricebookEntry.Product2Id;//Error on this line
                o.Quantity = oi.Quantity;
                o.unitPrice = oi.UnitPrice;
                 system.debug('oId ###'+oId);
                o.orderId = oId; 
                oItemsToInsert.add(o); 
              }
               
              if(oItemsToInsert.size()>0)
                insert oItemsToInsert;
             
               pageReference ref = ApexPages.currentPage(); 
               Id id = ref.getParameters().get('OrderId');
               ref.getParameters().clear();
               ref.getParameters().put('OrderId', id);  
               ref.setRedirect(true);
               return ref;
            
         }
         
         catch(Exception ex){
          
           ApexPages.addMessages(ex);
         
         }
         
         return null;
         
        }
public class ReductionOrderProductsExtensions {
  
    public List<OrderItem> orderItems{get;set;}
    public List<OrderItem> orderItems2{get;set;}
    public String oId;
    public List<OrderItemWrapper> orderItemList{get;set;}
    public List<Id> oiIds = new List<Id>();
    public List<OrderItem> selectedOItems = new list<OrderItem>();
    public List<OrderItem> oItemsToInsert = new list<OrderItem>();
    
    public ReductionOrderProductsExtensions(ApexPages.StandardController controller) {
          oId = ApexPages.currentPage().getParameters().get('OrderId');
          this.orderItemList  = new List<OrderItemWrapper>();  
          getOrderItemSet();  
      }
    
    public void getOrderItemSet()
     {        
         Order o = [select AccountId,Id from Order where Id = :oId];
         orderItems = [select orderId,Order.AccountId,Status__c,quantity,Product_Family__c,installed_billable_as_of__c,Vendor__c,Circuit_type__c,Circuit_Speed__c,Pricebookentry.Product2.Name,ListPrice,UnitPrice,Vendor_Changed__c,Installed_Quantity__c,Revenue_Type__c,Order.Status from OrderItem 
                            where Order.AccountId =: o.AccountId and Order.Status  = 'Activated' and quantity >0];
         set<String> uniqueOItems = new set<String>();
         
         for(OrderItem oi:orderItems){
             if(!uniqueOItems.contains(oi.Pricebookentry.Product2.Name + oi.Vendor__c + oi.Circuit_Speed__c + oi.Circuit_Type__c)){  
                 uniqueOItems.add(oi.Pricebookentry.Product2.Name + oi.Vendor__c + oi.Circuit_Speed__c + oi.Circuit_Type__c);
                  oiIds.add(oi.Id);
              }
           }   
         orderItems2 = [select orderId,Order.AccountId,Status__c,quantity,Product_Family__c,installed_billable_as_of__c,Vendor__c,Circuit_type__c,Circuit_Speed__c,PricebookEntry.Product2Id,Pricebookentry.Product2.Name,ListPrice,UnitPrice,Vendor_Changed__c,Installed_Quantity__c,Revenue_Type__c,Order.Status,Id from OrderItem 
                            where Id in: oiIds];
         for(OrderItem oi:orderItems2){
          this.orderItemList.add(new OrderItemWrapper(oi));
         }
     }
    
    public class OrderItemWrapper{
  
        public OrderItem oitem{get;set;}
  
        public Boolean selected{get;set;}
 
        public OrderItemWrapper(OrderItem o){
            this.oitem = o;
            this.selected = false;
        }
 
    }
    
    public PageReference save(){
     
     try{
          selectedOItems.clear();
         for(OrderItemWrapper owrapper : orderItemList){
            if(owrapper.selected == true)
             selectedOItems.add(owrapper.oitem);
           }
        system.debug('selectedOItems ###'+selectedOItems);
         for(OrderItem oi:selectedOItems){
             system.debug('oi ###'+oi);
            OrderItem o = new OrderItem();
             system.debug('o ###'+o);
             system.debug('oi.PricebookEntry.Product2Id ###'+ oi.PricebookEntry.Product2Id);
             system.debug('o.PricebookEntry.Product2Id ###'+ o.PricebookEntry.Product2Id); 
             o.PricebookEntry.Product2Id = oi.PricebookEntry.Product2Id; 
             system.debug('oi.PricebookEntry.Product2Id ###'+ oi.PricebookEntry.Product2Id);
            o.Quantity = oi.Quantity;
            o.unitPrice = oi.UnitPrice;
             system.debug('oId ###'+oId);
            o.orderId = oId; 
            oItemsToInsert.add(o); 
          }
          system.debug('oItemsToInsert ###'+oItemsToInsert);
            
         if(oItemsToInsert.size()>0)
            insert oItemsToInsert;
         
           pageReference ref = ApexPages.currentPage(); 
           Id id = ref.getParameters().get('OrderId');
           ref.getParameters().clear();
           ref.getParameters().put('OrderId', id);  
           ref.setRedirect(true);
           return ref;
        
     }
     
     catch(Exception ex){
      
       ApexPages.addMessages(ex);
      
     }
      
     return null;
     
    }
    
    public PageReference cancel(){
      
      return new PageReference('/' + oId);
    
    }
     
}
added 1305 characters in body
Source Link
sfdc
  • 13.8k
  • 19
  • 136
  • 218
Loading
Source Link
sfdc
  • 13.8k
  • 19
  • 136
  • 218
Loading