function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
sfdc007sfdc007 

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
 
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
Krishna SambarajuKrishna Sambaraju
Here is a sample test class you can use. Change the field names accordingly.
@isTest
   public class TestClass
   {
		static testMethod void ShouldReturnOppLineItemListForProducts()
	   {
			ECom_Product_Master__c ecomProdMaster = CreateEcomProductMaster();
			List<Products> prodList = CreateProductsList();
			
			//pass the data to the static method of the class to test.
			//change the classname below to the class in which your static method is
			List<OpportunityLineItem> oppLineItems = classname.OppLnItm(prodList);
			
			//Assert
			system.assertEquals(n, oppLineItems.size()); //Change n to the number you expect
			
	   }
	   //Method to create product master custom setting
	   static ECom_Product_Master__c CreateEcomProductMaster()
	   {
			ECom_Product_Master__c ecomProdMaster = new ECom_Product_Master__c(Product_Code__c = 'productCode', Designator__c = 'designator');
			insert ecomProdMaster;
			return ecomProdMaster;
	   }
	   //Method to create test data of product list
	   static List<Products> CreateProductsList()
	   {
			List<Products> prodList = new List<Products>();
			Products prods1 = new Products(field1='value1', field2='value2');//create products instance with the fields and values
			Products prods2 = new Products(field1='value1', field2='value2');//create products instance with the fields and values
			prodList.add(prods1);
			prodList.add(prods2);
			return prodList;
	   }
   }

Hope this helps.
sfdc007sfdc007
i tried the above getting the following error

Method does not exist or incorrect signature: ECOMOpportunityInbound.OppLnItm(List&lt;Product2&gt;)


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);


    
Krishna SambarajuKrishna Sambaraju
The code you shared is as below
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.
sfdc007sfdc007
Yes products is a inner class

global class Products{
        webservice string ECOM_PRODUCT_ID;             
        webservice string BOOKING;   
        webservice string SITE_COUNT;
    }



How to cover that method , pls help me
sfdc007sfdc007
MY APEX CLASS :


global without sharing class ECOMOpportunityInbound{
    // global static boolean EcomTriggerSkip = false;
    global class EcomRequest { 
        
        webservice String ECOM_TRANSACTION_ID;
        webservice String ECOM_QUOTE_TYPE;
        webservice String GCH_ID;
        webservice String OPPORTUNITY_NAME;        
        webservice String NASP_ID;
        webservice String OPPORTUNITY_ID; 
        webservice string SFDC_OPPORTUNITY_ID;       
        webservice list<Products>PRODUCT; 
        webservice string VEC_CONTACT_NAME;
        webservice string VEC_CONTACT_EMAIL;
        webservice string VEC_PHONE_NUMBER; 
        
    }
    
    global class EcomUpdateRequest {
        
        webservice String ECOM_TRANSACTION_ID;
        webservice String STAGE;
        webservice String COMPETITOR;
        webservice String CONTRACT_TERM;  
        webservice String CLOSE_REASON; 
        webservice String CLOSE_SUB_REASON;  
        webservice String ECOM_OPPTY_SHORT_ID;    
        webservice String ECOM_OPPORTUNITY_ID; 
    }
    
    global class Products{
        webservice string ECOM_PRODUCT_ID;             
        webservice string BOOKING;   
        webservice string SITE_COUNT;
    }
    
    global class EcomResponse{     
        
        webservice string MESSAGE;
        webservice string STATUS_CODE;
        webservice string OPPTY_Id;
        webservice string SFDC_OPPTY_ID;
        webservice string ECOM_TRANSACTION_ID;
    }   
    
    //Update eComm oppty based on eComm transaction Id and SFDC Oppty Id(Both Short and Long ID)
    
    webservice static EcomResponse EcomOpptyUpdateRequest(EcomUpdateRequest req) {
        
        EcomResponse res =new EcomResponse();
        Boolean CntrTrm = false;        
        try{            
            for(string ContTerm :label.eComm_Contract_Term.split(',')){
                if(ContTerm == req.CONTRACT_TERM){
                    CntrTrm = true;            
                }            
            }            
            if(req.STAGE != '5 Closed Won'){            //Invalid Stage
                res.Status_Code = 'VEC-007';              
                res.Message = 'Failure';  
                res.ECOM_TRANSACTION_ID = req.ECOM_TRANSACTION_ID;
            }
            else if(req.COMPETITOR != 'Other - Not known'){ //Invalid Competitor
                res.Status_Code = 'VEC-008';              
                res.Message = 'Failure';
                res.ECOM_TRANSACTION_ID = req.ECOM_TRANSACTION_ID;
            }       
            else if(req.CLOSE_REASON != 'Won: Product Offerings'){      //Invalid Close Reason
                res.Status_Code = 'VEC-010';              
                res.Message = 'Failure';
                res.ECOM_TRANSACTION_ID = req.ECOM_TRANSACTION_ID;
            }
            else if(req.CLOSE_SUB_REASON != 'Customer Specific Value Advantage'){       //Invalid Sub close reason
                res.Status_Code = 'VEC-011';              
                res.Message = 'Failure';
                res.ECOM_TRANSACTION_ID = req.ECOM_TRANSACTION_ID;
            }                      
            else if(!CntrTrm){                                      //Invalid Contract term
                res.Status_Code = 'VEC-009';              
                res.Message = 'Failure';
                res.ECOM_TRANSACTION_ID = req.ECOM_TRANSACTION_ID;
            }            
            else{      //Update eComm Opportunity      
                list<Opportunity> Updateopp = new list<Opportunity>() ;                        
                Updateopp=[Select Id,Competitor__c,StageName,Contract_Term__c,Close_Reason__c,Close_Sub_Reason__c,SFDC_Opportunity_ID__c,VEC_Transaction_Id__c  from Opportunity where (Id=:req.ECOM_OPPORTUNITY_ID or SFDC_Opportunity_ID__c =:req.ECOM_OPPTY_SHORT_ID) and VEC_Transaction_Id__c =:req.ECOM_TRANSACTION_ID];
                if(Updateopp.size()>0)
                {
                    Updateopp[0].StageName=req.STAGE;
                    Updateopp[0].Contract_Term__c=req.CONTRACT_TERM;
                    Updateopp[0].Competitor__c=req.COMPETITOR;
                    Updateopp[0].Close_Reason__c=req.CLOSE_REASON;
                    Updateopp[0].Close_Sub_Reason__c=req.CLOSE_SUB_REASON;
                    system.debug('Updateopp===>'+Updateopp);
                    Database.update(Updateopp); 
                    res.Status_Code = 'VEC-000';  
                    res.OPPTY_Id=Updateopp[0].Id;
                    res.SFDC_OPPTY_ID=Updateopp[0].SFDC_Opportunity_ID__c;
                    res.ECOM_TRANSACTION_ID = req.ECOM_TRANSACTION_ID;
                    res.Message = 'Success';                                
                }
                else if(req.ECOM_OPPORTUNITY_ID != null && req.ECOM_OPPORTUNITY_ID != ''){
                    Updateopp=[Select Id,Competitor__c,StageName,Contract_Term__c,Close_Reason__c,Close_Sub_Reason__c,SFDC_Opportunity_ID__c,VEC_Transaction_Id__c  from Opportunity where Id=:req.ECOM_OPPORTUNITY_ID and VEC_Transaction_Id__c =:req.ECOM_TRANSACTION_ID];
                    if(!(Updateopp.size()>0)){		//Invalid Long Oppty id
                        res.Status_Code = 'VEC-012';              
                        res.Message = 'Failure';                 
                        res.OPPTY_Id = req.ECOM_OPPORTUNITY_ID;
                        res.ECOM_TRANSACTION_ID = req.ECOM_TRANSACTION_ID;
                    }
                }                 
                else{													//Invalid Short Id
                    res.Status_Code = 'VEC-013';              
                    res.Message = 'Failure';                 
                    res.SFDC_OPPTY_ID = req.ECOM_OPPTY_SHORT_ID;
                    res.ECOM_TRANSACTION_ID = req.ECOM_TRANSACTION_ID;
                }                                             
            }        
        } catch (Exception e){                          
            res.MESSAGE = e.getMessage();
            res.ECOM_TRANSACTION_ID=req.ECOM_TRANSACTION_ID;
        }
        return res;
    }       
    
    //Create eComm opportunity
    
    webservice static EcomResponse EcomOpportunityCreationRequest(EcomRequest req) {  
        // EcomTriggerSkip=true;  
        SkipingHelper.skipTriggerOpportunityToRTSyncRecord=true; 
        EcomResponse resp =new EcomResponse();
        map<boolean,string>NaspMap = new map<boolean,string>();                
        string EcomOpptyOwnerId;           
        Map<string,list<Account>> AcntMap = new Map<string,list<Account>>();
        list<Account> lstAccount = new list<Account>();                
        list<ECom_Product_Master__c> lsteCommPrdMas = new list<ECom_Product_Master__c>();              
        try
        {   
            string QuoteType = req.ECOM_QUOTE_TYPE;
            Opportunity opp = new Opportunity(); 
            OpportunityLineItem oppline; 
            list<OpportunityLineItem> lstOpptyLine = new list<OpportunityLineItem>();
            list<OpportunityLineItem>lstOpLnItInsert = new list<OpportunityLineItem>();            
            Boolean Type = false; 
            if(QuoteType == 'Partial'){   //VEC Contact information is missing when Quote type is Partial 
                if((Req.VEC_CONTACT_NAME == Null || Req.VEC_CONTACT_NAME == '')&& (Req.VEC_CONTACT_EMAIL == Null || Req.VEC_CONTACT_EMAIL == '')&&(Req.VEC_PHONE_NUMBER == Null || Req.VEC_PHONE_NUMBER == '')){
                    resp.Status_Code = 'VEC-014';              
                    resp.Message = 'Faliure';
                    resp.ECOM_TRANSACTION_ID=req.ECOM_TRANSACTION_ID;
                    return resp;
                }                   
            }
            system.debug('req.ECOM_QUOTE_TYPE==>'+req.ECOM_QUOTE_TYPE);
            
            for(string QuType :label.eComm_Quote_Type.split(',')){
                if(QuoteType == QuType){
                    Type = true;
                }
            }
            system.debug('Type===>'+Type);
            if(!Type){                                                  //Invalid Quote Type
                resp.Status_Code = 'VEC-005';              
                resp.Message = 'Failure';
                resp.ECOM_TRANSACTION_ID=req.ECOM_TRANSACTION_ID; 
                return resp;
            }
            else{
                //Get Account object based on OpptyID or GchID or NaspId
                
                AcntMap = getAccount(req.OPPORTUNITY_ID,req.SFDC_OPPORTUNITY_ID,req.GCH_ID,req.Nasp_ID);
                system.debug('AcntMap===>'+AcntMap);
                if(AcntMap.containsKey('NotFound')){            //Nasp Not found
                    resp.Status_Code = 'VEC-001';              
                    resp.Message = 'Faliure';
                    resp.ECOM_TRANSACTION_ID=req.ECOM_TRANSACTION_ID;
                    return resp;
                }
                else if(AcntMap.containsKey('Invalid')){        //Invalid Account or Account not found
                    resp.Status_Code = 'VEC-002';              
                    resp.Message = 'Faliure';
                    resp.ECOM_TRANSACTION_ID=req.ECOM_TRANSACTION_ID;
                    return resp;
                }
                else if(AcntMap.containsKey('CenterManaged')){      //Center Managed NASP
                    resp.Status_Code = 'VEC-003';              
                    resp.Message = 'Faliure';
                    resp.ECOM_TRANSACTION_ID=req.ECOM_TRANSACTION_ID;
                    return resp;
                }
                else if(AcntMap.containsKey('GenericNASP')){        //Generic Nasp
                    resp.Status_Code = 'VEC-004';              
                    resp.Message = 'Faliure';
                    resp.ECOM_TRANSACTION_ID=req.ECOM_TRANSACTION_ID;
                    return resp;
                }               
                else{                    
                    lstAccount = AcntMap.get('Account');
                    //list<Products>lstProds = req.PRODUCT;
                    lstOpptyLine = OppLnItm(req.PRODUCT);
                    system.debug('lstOpptyLineReturn===>'+lstOpptyLine);
                    system.debug('lstAccount===>'+lstAccount);
                    //Assign Record type and Oppty owner based on Account Organisation
                    
                    if(lstOpptyLine.size()>0){                    
                        if(lstAccount[0].Organization__c == 'Medium Business'){
                            opp.RecordTypeId = RecordTypeHelper.getRecordTypeId('Opportunity','Medium Business Sales Opportunity');
                            EcomOpptyOwnerId=OpptyOwnerCheck(lstAccount); 
                        }
                        else{
                            opp.RecordTypeId = RecordTypeHelper.getRecordTypeId('Opportunity','Wireline Sales Opportunity');
                            if(lstAccount[0].Owner.IsActive == true){
                                EcomOpptyOwnerId=lstAccount[0].OwnerId; 
                            }
                            else{            //Account Not found for Inactive users
                                resp.Status_Code = 'VEC-001';              
                                resp.Message = 'Faliure';
                                resp.ECOM_TRANSACTION_ID=req.ECOM_TRANSACTION_ID;
                                return resp;
                            }
                        }
                        opp.AccountId = lstAccount[0].Id;                                                         
                        opp.Name=req.OPPORTUNITY_NAME;                
                        opp.CloseDate=Date.today().addDays(60);            
                        opp.NextStep='This opportunity was created by customer through eComm portal. If and when customer needs your help, you will be notified through Chatter notification or UOTM Task.';            
                        opp.StageName='1 Qualify';            
                        opp.Type='New Business';
                        opp.Answer_10__c='No';
                        opp.Opportunity_Origin__c = 'VEC Portal';
                        opp.VEC_Transaction_Id__c = req.ECOM_TRANSACTION_ID;                                                                               
                        if(opp!=null)
                        {    
                            //Insert eComm Opportunity 
                            
                            database.insert(opp);                     
                            system.debug('opp===>'+opp.Id);
                            Exchange_Rate__c exRate = [select Id, Currency_Code__c from Exchange_Rate__c where Currency_Code__c = 'usd' Limit 1];                        
                            for(OpportunityLineItem opLnIt : lstOpptyLine){ 
                                oppline = new OpportunityLineItem();
                                oppline.OpportunityId = opp.Id;                                
                                oppline.Local_Currency__c = exRate.Id;
                                oppline.Local_Booking__c = opLnIt.Booking__c;
                                oppline.Site_Count__c = opLnIt.Site_Count__c;
                                oppline.PricebookEntryId = opLnIt.PricebookEntryId;
                                if(opLnIt.Product_Designator__c != null){
                                    oppline.Product_Designator__c =opLnIt.Product_Designator__c;
                                }
                                lstOpLnItInsert.add(oppline);
                                system.debug('lstOpLnItInsert===>'+lstOpLnItInsert);
                            } 
                            
                            //Insert Oppty LineItem
                            
                            Database.insert(lstOpLnItInsert);  
                            system.debug('lstOpLnItInsert==>'+lstOpLnItInsert); 
                            
                            opp = [select Id, OwnerId,SFDC_Opportunity_ID__c from Opportunity where Id = :opp.Id ];   
                            opp.Keep_Manual_Primary_Flag__c=true;
                            opp.OwnerId = EcomOpptyOwnerId;
                            Database.update(opp);
                            
                            //Chatter Feed
                            
                            map <Id, String> chatterTextMap = new map <Id, String> ();
                            map <Id, set <Id>> mentionIdMap = new map <Id, set <Id>> ();
                            List<Id> lsmentionId = new List<Id>();
                            system.debug('opp==>'+opp);                       
                            PIPIntelHelper.skipChatterTriggers = true;
                            string OwnerId = opp.OwnerId;                                                 
                            string Subject;
                            string ContactName = req.VEC_CONTACT_NAME;                            
                            //ECOM_MB_OWNER__c dfOwner = [select Id from ECOM_MB_OWNER__c Limit 1];
                            user UserMgr = [SELECT Id, Manager.Id,Manager__c, Name FROM User where Id = :OwnerId];
                            lsmentionId.add(UserMgr.Id);
                            lsmentionId.add(UserMgr.Manager.Id);                            
                            if(lstAccount[0].Organization__c == 'Medium Business'){
                                for(string dfuser:label.MB_VEC_New_Oppty_Chatter_Recipients.split(',')){
                                    lsmentionId.add(dfuser);
                                }
                                if(req.ECOM_QUOTE_TYPE == 'Partial'){
                                    Subject = '\n\nDear '+UserMgr.Name+', \nThis opportunity was created in SFDC as a result of a customer-driven buying activity in the VEC Portal. Get in touch with the customer contact shown below to move the opportunity forward. You can locate the ProQuest quote that was created for this opportunity via the ProQuest Quotes hyperlink on top of the opportunity detail page.'+'@'+UserMgr.Manager__c+'\r\n'+req.VEC_CONTACT_NAME+'\r\n'+req.VEC_CONTACT_EMAIL+'\r\n'+req.VEC_PHONE_NUMBER;
                                    chatterTextMap.put(opp.Id,Subject);
                                    mentionIdMap.put(opp.Id,new set <Id>(lsmentionId));
                                }
                                else {
                                    Subject = '\n\nDear '+UserMgr.Name+', \nThis opportunity was created in SFDC as a result of a customer-driven buying activity in the VEC Portal. No action is needed from you at this point. VEC Portal will continue to move this opportunity forward with creation of a quote and eventual order for this opportunity, automatically. In case this auto-process runs into any issues in either the quoting or the ordering system, you will be notified via a Universal Order Task Management (UOTM) task in SFDC along with related details.'+'@'+UserMgr.Manager__c;
                                    chatterTextMap.put(opp.Id,Subject);
                                    mentionIdMap.put(opp.Id,new set <Id>(lsmentionId));
                                }
                            }
                            else{
                                if(req.ECOM_QUOTE_TYPE == 'Partial'){
                                    Subject = '\n\nDear '+UserMgr.Name+', \nThis opportunity was created in SFDC as a result of a customer-driven buying activity in the VEC Portal. Get in touch with the customer contact shown below to move the opportunity forward. You can locate the ProQuest quote that was created for this opportunity via the ProQuest Quotes hyperlink on top of the opportunity detail page.'+'@'+UserMgr.Manager__c+'\r\n'+req.VEC_CONTACT_NAME+'\r\n'+req.VEC_CONTACT_EMAIL+'\r\n'+req.VEC_PHONE_NUMBER;
                                    chatterTextMap.put(opp.Id,Subject);
                                    mentionIdMap.put(opp.Id, new set <Id>(lsmentionId));
                                }
                                else {
                                    Subject = '\n\nDear '+UserMgr.Name+', \nThis opportunity was created in SFDC as a result of a customer-driven buying activity in the VEC Portal. No action is needed from you at this point. VEC Portal will continue to move this opportunity forward with creation of a quote and eventual order for this opportunity, automatically. In case this auto-process runs into any issues in either the quoting or the ordering system, you will be notified via a Universal Order Task Management (UOTM) task in SFDC along with related details.'+'@'+UserMgr.Manager__c;
                                    chatterTextMap.put(opp.Id,Subject);
                                    mentionIdMap.put(opp.Id,new set <Id>(lsmentionId));
                                }
                            }
                            if(chatterTextMap.size()>0){
                                system.debug('mentionIdMap==>'+mentionIdMap);
                                system.debug('chatterTextMap==>'+chatterTextMap);  
                                CommunityUtility.postCustomFeedItem (mentionIdMap, chatterTextMap, 'AllUsers');
                                resp.Status_Code = 'VEC-000';  
                                resp.OPPTY_Id=opp.Id;
                                resp.SFDC_OPPTY_ID = opp.SFDC_Opportunity_ID__c;
                                resp.Message = 'Success'; 
                                resp.ECOM_TRANSACTION_ID=req.ECOM_TRANSACTION_ID;
                            }                            
                        }                       
                    }
                    else{
                        resp.Status_Code = 'VEC-006';              
                        resp.Message = 'Failure';
                        resp.ECOM_TRANSACTION_ID=req.ECOM_TRANSACTION_ID;
                    }
                } 
            }
        }   catch (Exception e) {                         
            resp.Message = e.getMessage();
            resp.ECOM_TRANSACTION_ID=req.ECOM_TRANSACTION_ID;
        }
        system.debug('Finalresp====>'+resp);
        return resp;
    } 
    
    //Function to get Account object based on Opportunity or GCH
    
    public static Map<string,list<Account>> getAccount(string OpptyId, string SFDCOpptyId, string GCHID, string NaspId){
        string AccountId;
        Map<string,list<Account>> lstAccMap = new Map<string,list<Account>>();
        list<Account> lstAcc = new list<Account>();
        list<Opportunity>lstOppty = new list<Opportunity>();
        if((OpptyId != null && OpptyId != '')||(SFDCOpptyId != null && SFDCOpptyId != '')){     //Get Account based on OpptyID
            lstOppty = [SELECT Id,AccountId FROM Opportunity where Id =:OpptyId or SFDC_Opportunity_ID__c =:SFDCOpptyId Limit 1];
            if(lstOppty.size()>0){
                AccountId = lstOppty[0].AccountId;
            }
            if(AccountId != null && AccountId != ''){                
                lstAcc = [select Id,Organization__c,Owner.IsActive,OwnerId,MB_Account_Owner__c from Account where Id=:AccountId];
                if(lstAcc.size()>0){
                    lstAccMap.put('Account',lstAcc);
                    return lstAccMap;
                }
            }
        }
        else if(GCHID != null && GCHID != ''){          //Get Account based on GCHID
            lstAcc = [SELECT Id,Organization__c,OwnerId,Owner.IsActive,MB_Account_Owner__c FROM Account where GCH_ID__c=:GCHID LIMIT 1];
            if(lstAcc.size()>0){
                lstAccMap.put('Account', lstAcc);
                return lstAccMap;
            }
        }
        if(lstAcc.isEmpty()){                                           //Get Account based on NaspID
            list<ALL_NASP_IDs__c> lstAllNasp = new list<ALL_NASP_IDs__c>();
            lstAllNasp = [Select Id,Center_Managed__c,Generic_NASP__c FROM ALL_NASP_IDs__c where Name=:NaspId];
            if(lstAllNasp.size()>0){
                if(lstAllNasp[0].Center_Managed__c == true){                //Check if nasp is CenterManaged or Generic
                    lstAccMap.put('CenterManaged', lstAcc);
                    return lstAccMap;
                }
                else if(lstAllNasp[0].Generic_NASP__c == 'TRUE'){
                    lstAccMap.put('GenericNASP', lstAcc);
                    return lstAccMap;
                }
                else{                                                       //Not CenterManaged or Generic Nasp
                    lstAcc = [SELECT Id,Organization__c,OwnerId,Owner.IsActive,MB_Account_Owner__c,Primary_Account__c FROM Account where Account_NASP_Name__c=:NaspId and Primary_Account__c = true order by CreatedDate desc Limit 1];
                    if(lstAcc.size()>0){                        
                        lstAccMap.put('Account', lstAcc);
                        return lstAccMap;
                    }
                    else{
                        lstAcc = [SELECT Id,Organization__c,OwnerId,Owner.IsActive,MB_Account_Owner__c,Primary_Account__c FROM Account where Account_NASP_Name__c=:NaspId];
                        if(lstAcc.size()==1){                                
                            lstAccMap.put('Account', lstAcc);
                            return lstAccMap;
                        }
                        else{
                            lstAccMap.put('Invalid',lstAcc);        //Invalid Account
                            system.debug('lstAccMap===>'+lstAccMap);
                            return lstAccMap;                            
                        }
                    }                    
                }
            }
            else{                               //Invalid Nasp
                lstAccMap.put('NotFound',lstAcc);
                return lstAccMap;
            }
        }
        return lstAccMap;        
    }   
    
    //Function to set Newly Created Opportuniy Owner based on Account Organisation
    
    public static string OpptyOwnerCheck(list<Account> lstAccnt){         
        ECOM_MB_OWNER__c DefaultOwner;
        string OpptyOwner;        
        string MBIntgUserID = Label.MB_Integration_User_ID;
        system.debug('MBIntgUserID==>'+MBIntgUserID);        
        Account acc;  
        List<Opportunity> lstOppty =new List<Opportunity>();
        if(lstAccnt.size()>0){            
            if(lstAccnt[0].Organization__c == 'Medium Business' && lstAccnt[0].OwnerId != null && lstAccnt[0].OwnerId != MBIntgUserID){
                OpptyOwner = lstAccnt[0].OwnerId;
            }
            else{
                lstOppty = [select Id,OwnerId,CreatedDate from Opportunity where AccountId=:lstAccnt[0].Id and StageName not in('5 Closed Won','5 Closed Lost','5 Closed Disqualified') and  Owner.IsActive=true and OwnerId <>:MBIntgUserID  order by CreatedDate desc Limit 1];
                if(lstOppty.size()>0){
                    OpptyOwner = lstOppty[0].OwnerId;
                }
                else{
                    DefaultOwner = ECOM_MB_OWNER__c.getValues('Default MB Owner');
                    OpptyOwner = DefaultOwner.User_Id__c;
                }                
            }
        }       
        return OpptyOwner;          
    } 
    
    //Function to create oppty line item(Oppty Products)
    
    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;        
    }  
    
}
Krishna SambarajuKrishna Sambaraju
In your class you have the following inner class.
global class Products
{ 
	webservice string ECOM_PRODUCT_ID; 
	webservice string BOOKING; 
	webservice string SITE_COUNT; 
}
The static method is expecting a list of instances of this class. I don't know what is the mapping between the variables in this class and the fields in Product2 object.
You might need to create an instance of this class using the fields of product2 record you create as below.
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<Products> prodList = new List<Products>();

//change or add the mapped fields accordingly.
prodList.add(new Products(ECOM_PRODUCT_ID = p.mappedProductId, BOOKING = p.mappedBooking));
and pass that list to the method in the test class.

Hope this helps.


 
Krishna SambarajuKrishna Sambaraju
You need to use the followng syntax to create a list of the inner class instances of a main class and also there is no constructor to the inner class.
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.

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');

List<ECOMOpportunityInbound.Products> prodList = new List<ECOMOpportunityInbound.Products>();
        ECOMOpportunityInbound.Products prod = new ECOMOpportunityInbound.Products();
        prod.ECOM_PRODUCT_ID = p.mappingProductId;
        prod.BOOKING = p.mappingBooking;
        prod.SITE_COUNT = p.mappingSiteCount;
        prodList.add(prod);

Hope this helps you.
 
Leo BarnoskiLeo Barnoski
Is this help you in your online business? I am also looking for my Flying dutchman ship (https://omhusa.com/productsdetails.asp?item=T389) model website.