You need to sign in to do that
Don't have an account?

Hi friends, can you help me with syntax of following test method?
public static void insertOrderProducts(Order order, Id serviceFormId,boolean isDealerConsumption){
/* if(isDealerConsumption == true){
order.Pricebook2Id ='01s2h000000DQSAAA4';
} */
system.debug('@@@OrderProducts');
List<OrderItem> orderProductsToInsert = new List<OrderItem>();
Set<Id> productIds = new Set<Id>();
system.debug('@@@productIds '+productIds);
Map<Id, PricebookEntry> productIdVsPBE = new Map<Id, PricebookEntry>();
//Added by sumith sharma on 10 -march-2021
string strProductType = (isDealerConsumption ? GlobalConstants.PRODUCT_TYPE_DC : GlobalConstants.PRODUCT_TYPE_INCLUSION);
List<SR_Products__c> srProducts = [Select id,Product__c,Service_Form__r.Order__r.Pricebook2Id,Quantify__c, Service_Form__c
From SR_Products__c
Where Service_Form__c =: serviceFormId
And Product__c != null
// And Product_Type__c = :GlobalConstants.PRODUCT_TYPE_INCLUSION
And Product_Type__c = :strProductType
And isConverted__c = false];
system.debug('@@@OrderProducts2 '+srProducts);
for(SR_Products__c srp : srProducts){
productIds.add(srp.Product__c);
}
for(PricebookEntry pbe : [Select Id, Product2Id,Pricebook2Id, UnitPrice From PricebookEntry Where Pricebook2Id =: order.Pricebook2Id AND Product2Id IN: productIds]){
system.debug('@@1234');
system.debug(pbe);
productIdVsPBE.put(pbe.Product2Id, pbe);
}
if(!productIdVsPBE.isEmpty()){
for(SR_Products__c srp : srProducts){
if(productIdVsPBE.containsKey(srp.Product__c)){
OrderItem item = new OrderItem(OrderId = order.Id,
Product2Id = srp.Product__c,
Quantity = srp.Quantify__c != null ? srp.Quantify__c : 1,
PriceBookEntryId = productIdVsPBE.get(srp.Product__c).Id,
ListPrice = productIdVsPBE.get(srp.Product__c).UnitPrice,
UnitPrice = productIdVsPBE.get(srp.Product__c).UnitPrice,
Line_Discount__c = 100);
orderProductsToInsert.add(item);
system.debug('@@@orderproductsize '+orderProductsToInsert);
}
}
}
// if(orderProductsToInsert.Size() > 0){
system.debug('@@@orderproductsize '+orderProductsToInsert );
Insert orderProductsToInsert;
// }
}
/* if(isDealerConsumption == true){
order.Pricebook2Id ='01s2h000000DQSAAA4';
} */
system.debug('@@@OrderProducts');
List<OrderItem> orderProductsToInsert = new List<OrderItem>();
Set<Id> productIds = new Set<Id>();
system.debug('@@@productIds '+productIds);
Map<Id, PricebookEntry> productIdVsPBE = new Map<Id, PricebookEntry>();
//Added by sumith sharma on 10 -march-2021
string strProductType = (isDealerConsumption ? GlobalConstants.PRODUCT_TYPE_DC : GlobalConstants.PRODUCT_TYPE_INCLUSION);
List<SR_Products__c> srProducts = [Select id,Product__c,Service_Form__r.Order__r.Pricebook2Id,Quantify__c, Service_Form__c
From SR_Products__c
Where Service_Form__c =: serviceFormId
And Product__c != null
// And Product_Type__c = :GlobalConstants.PRODUCT_TYPE_INCLUSION
And Product_Type__c = :strProductType
And isConverted__c = false];
system.debug('@@@OrderProducts2 '+srProducts);
for(SR_Products__c srp : srProducts){
productIds.add(srp.Product__c);
}
for(PricebookEntry pbe : [Select Id, Product2Id,Pricebook2Id, UnitPrice From PricebookEntry Where Pricebook2Id =: order.Pricebook2Id AND Product2Id IN: productIds]){
system.debug('@@1234');
system.debug(pbe);
productIdVsPBE.put(pbe.Product2Id, pbe);
}
if(!productIdVsPBE.isEmpty()){
for(SR_Products__c srp : srProducts){
if(productIdVsPBE.containsKey(srp.Product__c)){
OrderItem item = new OrderItem(OrderId = order.Id,
Product2Id = srp.Product__c,
Quantity = srp.Quantify__c != null ? srp.Quantify__c : 1,
PriceBookEntryId = productIdVsPBE.get(srp.Product__c).Id,
ListPrice = productIdVsPBE.get(srp.Product__c).UnitPrice,
UnitPrice = productIdVsPBE.get(srp.Product__c).UnitPrice,
Line_Discount__c = 100);
orderProductsToInsert.add(item);
system.debug('@@@orderproductsize '+orderProductsToInsert);
}
}
}
// if(orderProductsToInsert.Size() > 0){
system.debug('@@@orderproductsize '+orderProductsToInsert );
Insert orderProductsToInsert;
// }
}
Hi Rahul,
Please let me know what error you are facing and at which line.
Regards,
Priya Ranjan