You need to sign in to do that
Don't have an account?
sfdc007
Public static method coverage in test class
Hi,
I have a apex class where i am not able to cover the following method for which i need help on it
Kindly help me how to cover this method
Thanks in Advance
I have a apex class where i am not able to cover the following method for which i need help on it
Kindly help me how to cover this method
public static list<OpportunityLineItem> OppLnItm(list<Products> lstProd){ ECom_Product_Master__c eCommPrdMas; list<OpportunityLineItem>lstOppLnItem = new list<OpportunityLineItem>(); set<string> eCommProdId = new set<string>(); set<string>PrdDeg = new set<string>(); map<string,string>PriceBookMap = new map<string,string>(); map<string,Products>ProdMap = new map<string,Products>(); map<string,string> PrDesgMap = new map<string,string>(); list<PricebookEntry>lstPriceBookId = new list<PricebookEntry>(); list<Product_Designator__c> lstProdDesg = new list<Product_Designator__c>(); string ProdDesg,ProdId; if(lstProd.size()>0){ for(Products Pr : lstProd){ decimal SiteCnt = 0, Booking = 0; eCommPrdMas = ECom_Product_Master__c.getValues(Pr.ECOM_PRODUCT_ID); if(eCommPrdMas != null){ ProdId = eCommPrdMas.Product_Code__c; ProdDesg = eCommPrdMas.Designator__c; } else{ system.debug('No Products====>'+lstOppLnItem); return lstOppLnItem; } Products tempProd = new Products(); if(ProdMap.get(ProdId)!=null){ tempProd = ProdMap.get(ProdId); Booking = decimal.valueOf(tempProd.BOOKING)+decimal.valueOf(Pr.BOOKING); tempProd.BOOKING = string.valueOf(Booking); SiteCnt = decimal.valueOf(tempProd.SITE_COUNT)+decimal.valueOf(Pr.SITE_COUNT); tempProd.SITE_COUNT = string.valueOf(SiteCnt); ProdMap.put(ProdId, tempProd); } else{ tempProd = Pr; ProdMap.put(ProdId, tempProd); } eCommProdId.add(ProdId); PrdDeg.add(ProdDesg); PrDesgMap.put(ProdDesg, ProdId); } if(eCommProdId.size()>0){ lstPriceBookId = [SELECT Id, Product2.Product_ID__c FROM PricebookEntry where Pricebook2Id in (SELECT Id FROM Pricebook2 where name = 'Wireline Price Book') and Product2Id in (SELECT Id FROM Product2 where Product_ID__c =:eCommProdId)]; system.debug('lstPriceBookId===>'+lstPriceBookId); if(lstPriceBookId.size()>0){ lstProdDesg = [select Id, Name from Product_Designator__c where Name =:PrdDeg]; for(PricebookEntry PrBkEn: lstPriceBookId){ PriceBookMap.put(PrBkEn.Product2.Product_ID__c,PrBkEn.Id); } for(Product_Designator__c prDe :lstProdDesg){ if(PrDesgMap.size()>0){ string PId; PId = PrDesgMap.get(prDe.Name); PrDesgMap.put(PId, prDe.Id); } } for(string PrdId :eCommProdId){ Products prlist = new Products(); OpportunityLineItem OpptyLnIt = new OpportunityLineItem(); OpptyLnIt.PricebookEntryId = PriceBookMap.get(PrdId); prlist = ProdMap.get(PrdId); OpptyLnIt.Booking__c = decimal.valueOf(prlist.BOOKING); OpptyLnIt.Site_Count__c = decimal.valueOf(prlist.SITE_COUNT); if(PrDesgMap.get(PrdId)!=null){ OpptyLnIt.Product_Designator__c = PrDesgMap.get(PrdId); } lstOppLnItem.add(OpptyLnIt); } } } } system.debug('lstOppLnItem====>'+lstOppLnItem); return lstOppLnItem; }
Thanks in Advance
Hope this helps.
Method does not exist or incorrect signature: ECOMOpportunityInbound.OppLnItm(List<Product2>)
MY TEST CLASS :
//Create Product
product2 p = new product2(Name='Identity & Access Management Pro Serv',
Product_ID__c='5743-5290 ',ProductCode='5743-5290',
IsActive=true,PS_Opty__c=true, PS_Required__c=true,
CW_Quote_Product__c=true, PR1__c='Wireline',
USEC_Product__c='PR_PRO_SERVICES');
insert p;
List<product2>prod = new List<product2>();
prod.add(p);
//Create Ecom Product Master
ECom_Product_Master__c ecomProdMaster = new ECom_Product_Master__c(Product_Code__c = 'productCode', Designator__c = 'designator');
insert ecomProdMaster;
ECOMOpportunityInbound evond=new ECOMOpportunityInbound();
List<OpportunityLineItem> oppLineItems = ECOMOpportunityInbound.OppLnItm(prod);
public static list<OpportunityLineItem> OppLnItm(list<Products> lstProd)
I am not sure what this list<Products> is. Is Products a custom class and in your test data you are creating products using the Product2 object.
Check exactly which list you are passing to the static method. The method is expecting a parameter List<Products> and you are passing List<Product2> to it. That is why you are getting the error.
global class Products{
webservice string ECOM_PRODUCT_ID;
webservice string BOOKING;
webservice string SITE_COUNT;
}
How to cover that method , pls help me
You might need to create an instance of this class using the fields of product2 record you create as below. and pass that list to the method in the test class.
Hope this helps.
So change the following lines of above code
List<Products> prodList = new List<Products>(); //change or add the mapped fields accordingly.
prodList.add(new Products(ECOM_PRODUCT_ID = p.mappedProductId, BOOKING = p.mappedBooking));
as below.
Hope this helps you.