You need to sign in to do that
Don't have an account?
ayvak
how to insert below method in test class... pls help me
public List<OpportunityLineItem>createservicelist(Id contractId, Id OpportunityId)
{
List<OpportunityLineItem> proposedserviceList = new List<OpportunityLineItem>();
String psc = '';
if(!lstLineItems.isEmpty() || testFlag)
{
List<GetInstalledServiceWebService.InstalledServiceRecord> instSvcList = new List<GetInstalledServiceWebService.InstalledServiceRecord>();
System.debug('contractObj.Sub_Line_of_Business__c '+contractObj.Sub_Line_of_Business__c);
if(contractObj.Sub_Line_of_Business__c == 'Roll Off')
{
instSvcList = lstLineItems;
psc = 'Rolloff';
system.debug('qqqqqqqqqqqqqqqqq'+instSvcList.size());
}
else if (contractObj.Sub_Line_of_Business__c == 'Commercial')
{
instSvcList = lstNonRecurringLineItems;
psc = 'Commercial';
}
system.debug('instSvcList---' + instSvcList);
system.debug('size---' + instSvcList.size());
Map<Id, Fee_Table__c> feeMap = getFees(contractObj.Line_of_Business__c, contractObj.Sub_Line_of_Business__c, contractObj.Market_Area__c, contractObj.Zip_Code_Table__c);
system.debug('### maped successfully ###');
Set<Id> prodIds = new Set<Id>();
for (Product2 svc : lstProd)
{
prodIds.add(svc.Id);
}
Map<Id, Id> prodPEMap = new Map<Id, Id>();
if(prodIds.size() > 0)
{
List<PriceBookEntry> peList = [select Id, Product2Id from PriceBookEntry where Product2Id IN: prodIds];
for(PriceBookEntry pe: peList)
{
prodPEMap.put(pe.Product2Id, pe.Id);
}
}
Map<String, Id> rtMapFee = rtMap('Fee_Table__c');
for (GetInstalledServiceWebService.InstalledServiceRecord lst : instSvcList)
{
OpportunityLineItem proposedservices = new OpportunityLineItem();
System.debug('**** lst.equipmentCount = ' + lst.equipmentCount);
proposedservices.Quantity__c = ((lst.equipmentCount == null || Decimal.valueOf(lst.equipmentCount) == 0) ? 1 : Decimal.valueOf(lst.equipmentCount));
System.debug('*** proposedservices.Quantity__c = ' + proposedservices.Quantity__c);
proposedservices.Qty_for_Delivery__c = proposedservices.Quantity__c;
proposedservices.Qty_WM_Owns_Container__c = proposedservices.Quantity__c;
proposedservices.Product_Service_Type__c = psc;
proposedservices.Estimated_Value__c = lst.extCostAmount;
proposedservices.Type__c = lst.TPType;
for (Product2 svc : lstProd)
{
if ((svc.Conversion_Source_ID__c == lst.RserviceGUID && svc.Type__c == 'Service') || testFlag)//Example 3149
{
proposedservices.Quantity = ((lst.equipmentCount == null || Decimal.valueOf(lst.equipmentCount) == 0) ? 1 : Decimal.valueOf(lst.equipmentCount));
proposedservices.PriceBookEntryId = prodPEMap.get(svc.Id);
if(proposedservices.Type__c == 'Permanent')
{
system.debug('===in Permanent=='+lst.extCostAmount);
proposedservices.UnitPrice = lst.extCostAmount;
}
else
{
system.debug('===in Temporary/Not permanent=='+lst.extCostAmount);
proposedservices.UnitPrice = 0.0;
}
proposedservices.Service__c = svc.Id;
if(svc.Product_Service_Categories__c != null)
{
System.debug('********* svc.Product_Service_Categories__c = ' + svc.Product_Service_Categories__c);
String[] values = svc.Product_Service_Categories__c.split(';');
System.debug('********* values = ' + values);
proposedservices.Product_Service_Type__c = values[0];
}
proposedservices.Material_Description__c = svc.Material__c;
if (svc.Material__c != null)
{
Material2CategoryMapping__c matcat = Material2CategoryMapping__c.getInstance(svc.Material__c);
if(matcat != null)
{
proposedservices.Material_Category__c = matcat.Material_Category__c;
}
}
//RY:
Fee_Table__c fee = null;
if(feeMap != null && feeMap.size() > 0 && rtMapFee.size() > 0 && rtMapFee.get(proposedservices.Product_Service_Type__c) != null)
{
fee = feeMap.get(rtMapFee.get(proposedservices.Product_Service_Type__c));
}
System.debug('Fee increateservicelist' + fee);
if(contractObj.Sub_Line_of_Business__c == 'Commercial' && fee != null)
{
proposedservices.Extra_Pickup_Fee_Type__c = 'Yard';
Decimal prodSize = 0;
if(svc.Size__c != null && svc.Size__c != 'NOT APPLICABLE')
{
prodSize = Decimal.valueOf(svc.Size__c);
}
if( prodSize >= 2 && prodSize <= 10)
{
if(fee.Extra_Pickup_Fee__c != null && fee.Extra_Pickup_Fee_per_yard__c != null)
{
proposedservices.Extra_Pickup_Fee__c = fee.Extra_Pickup_Fee__c + (fee.Extra_Pickup_Fee_per_yard__c * prodSize);
}
}
else
{
if(fee.Extra_Pickup_Fee__c != null)
{
proposedservices.Extra_Pickup_Fee__c = fee.Extra_Pickup_Fee__c;
}
}
}
else
{
proposedservices.Extra_Pickup_Fee__c = fee == null ? null : fee.Extra_Pickup_Fee__c;
proposedservices.Extra_Pickup_Fee_Type__c = fee == null ? null : fee.Extra_Pickup_Fee_Type__c;
}
break;
}
}
proposedservices.OpportunityId = OpportunityId;
proposedservices.Suggested_Service_Day__c = getSuggestedServiceDay(lst);
proposedservices.Frequency__c = lst.serviceCount;
proposedservices.Occurs__c = Utility.TransformOccursValue(lst.serviceOccursCd);
proposedservices.Auto__c = lst.autoCd;
if(contractObj.Sub_Line_of_Business__c == 'Commercial'&&(lst.autoCd=='N'||lst.autoCd=='T'))
{
if(lst.autoCd=='N')
proposedservices.Occurs__c='On Call';
if(lst.autoCd=='T')
proposedservices.Occurs__c='Ticketed';
}
system.debug('==='+lst.applyRatePerContainer);
if(lst.applyRatePerContainer != null)
{
proposedservices.Apply_Rate_Per_Container__c = lst.applyRatePerContainer; //OR
}
if(lst.MASContractLineId != null)
{
proposedservices.MAS_Contract_Line_ID__c = lst.MASContractLineId; //OR
}
proposedservices.Rate__c = lst.extCostAmount;//TODO
proposedservices.Haul_Rate__c = lst.extCostAmount;
proposedservices.Configured__c = true;
if(proposedservices.Service__c != null && proposedservices.Product_Service_Type__c != null && proposedservices.Product_Service_Type__c != '')
{
proposedserviceList.add(proposedservices);
}
}
if(!proposedserviceList.isEmpty())
{
insert proposedserviceList;
system.debug('!!!proposed service list is inserted!!!');
}
}
return proposedserviceList;
}
{
List<OpportunityLineItem> proposedserviceList = new List<OpportunityLineItem>();
String psc = '';
if(!lstLineItems.isEmpty() || testFlag)
{
List<GetInstalledServiceWebService.InstalledServiceRecord> instSvcList = new List<GetInstalledServiceWebService.InstalledServiceRecord>();
System.debug('contractObj.Sub_Line_of_Business__c '+contractObj.Sub_Line_of_Business__c);
if(contractObj.Sub_Line_of_Business__c == 'Roll Off')
{
instSvcList = lstLineItems;
psc = 'Rolloff';
system.debug('qqqqqqqqqqqqqqqqq'+instSvcList.size());
}
else if (contractObj.Sub_Line_of_Business__c == 'Commercial')
{
instSvcList = lstNonRecurringLineItems;
psc = 'Commercial';
}
system.debug('instSvcList---' + instSvcList);
system.debug('size---' + instSvcList.size());
Map<Id, Fee_Table__c> feeMap = getFees(contractObj.Line_of_Business__c, contractObj.Sub_Line_of_Business__c, contractObj.Market_Area__c, contractObj.Zip_Code_Table__c);
system.debug('### maped successfully ###');
Set<Id> prodIds = new Set<Id>();
for (Product2 svc : lstProd)
{
prodIds.add(svc.Id);
}
Map<Id, Id> prodPEMap = new Map<Id, Id>();
if(prodIds.size() > 0)
{
List<PriceBookEntry> peList = [select Id, Product2Id from PriceBookEntry where Product2Id IN: prodIds];
for(PriceBookEntry pe: peList)
{
prodPEMap.put(pe.Product2Id, pe.Id);
}
}
Map<String, Id> rtMapFee = rtMap('Fee_Table__c');
for (GetInstalledServiceWebService.InstalledServiceRecord lst : instSvcList)
{
OpportunityLineItem proposedservices = new OpportunityLineItem();
System.debug('**** lst.equipmentCount = ' + lst.equipmentCount);
proposedservices.Quantity__c = ((lst.equipmentCount == null || Decimal.valueOf(lst.equipmentCount) == 0) ? 1 : Decimal.valueOf(lst.equipmentCount));
System.debug('*** proposedservices.Quantity__c = ' + proposedservices.Quantity__c);
proposedservices.Qty_for_Delivery__c = proposedservices.Quantity__c;
proposedservices.Qty_WM_Owns_Container__c = proposedservices.Quantity__c;
proposedservices.Product_Service_Type__c = psc;
proposedservices.Estimated_Value__c = lst.extCostAmount;
proposedservices.Type__c = lst.TPType;
for (Product2 svc : lstProd)
{
if ((svc.Conversion_Source_ID__c == lst.RserviceGUID && svc.Type__c == 'Service') || testFlag)//Example 3149
{
proposedservices.Quantity = ((lst.equipmentCount == null || Decimal.valueOf(lst.equipmentCount) == 0) ? 1 : Decimal.valueOf(lst.equipmentCount));
proposedservices.PriceBookEntryId = prodPEMap.get(svc.Id);
if(proposedservices.Type__c == 'Permanent')
{
system.debug('===in Permanent=='+lst.extCostAmount);
proposedservices.UnitPrice = lst.extCostAmount;
}
else
{
system.debug('===in Temporary/Not permanent=='+lst.extCostAmount);
proposedservices.UnitPrice = 0.0;
}
proposedservices.Service__c = svc.Id;
if(svc.Product_Service_Categories__c != null)
{
System.debug('********* svc.Product_Service_Categories__c = ' + svc.Product_Service_Categories__c);
String[] values = svc.Product_Service_Categories__c.split(';');
System.debug('********* values = ' + values);
proposedservices.Product_Service_Type__c = values[0];
}
proposedservices.Material_Description__c = svc.Material__c;
if (svc.Material__c != null)
{
Material2CategoryMapping__c matcat = Material2CategoryMapping__c.getInstance(svc.Material__c);
if(matcat != null)
{
proposedservices.Material_Category__c = matcat.Material_Category__c;
}
}
//RY:
Fee_Table__c fee = null;
if(feeMap != null && feeMap.size() > 0 && rtMapFee.size() > 0 && rtMapFee.get(proposedservices.Product_Service_Type__c) != null)
{
fee = feeMap.get(rtMapFee.get(proposedservices.Product_Service_Type__c));
}
System.debug('Fee increateservicelist' + fee);
if(contractObj.Sub_Line_of_Business__c == 'Commercial' && fee != null)
{
proposedservices.Extra_Pickup_Fee_Type__c = 'Yard';
Decimal prodSize = 0;
if(svc.Size__c != null && svc.Size__c != 'NOT APPLICABLE')
{
prodSize = Decimal.valueOf(svc.Size__c);
}
if( prodSize >= 2 && prodSize <= 10)
{
if(fee.Extra_Pickup_Fee__c != null && fee.Extra_Pickup_Fee_per_yard__c != null)
{
proposedservices.Extra_Pickup_Fee__c = fee.Extra_Pickup_Fee__c + (fee.Extra_Pickup_Fee_per_yard__c * prodSize);
}
}
else
{
if(fee.Extra_Pickup_Fee__c != null)
{
proposedservices.Extra_Pickup_Fee__c = fee.Extra_Pickup_Fee__c;
}
}
}
else
{
proposedservices.Extra_Pickup_Fee__c = fee == null ? null : fee.Extra_Pickup_Fee__c;
proposedservices.Extra_Pickup_Fee_Type__c = fee == null ? null : fee.Extra_Pickup_Fee_Type__c;
}
break;
}
}
proposedservices.OpportunityId = OpportunityId;
proposedservices.Suggested_Service_Day__c = getSuggestedServiceDay(lst);
proposedservices.Frequency__c = lst.serviceCount;
proposedservices.Occurs__c = Utility.TransformOccursValue(lst.serviceOccursCd);
proposedservices.Auto__c = lst.autoCd;
if(contractObj.Sub_Line_of_Business__c == 'Commercial'&&(lst.autoCd=='N'||lst.autoCd=='T'))
{
if(lst.autoCd=='N')
proposedservices.Occurs__c='On Call';
if(lst.autoCd=='T')
proposedservices.Occurs__c='Ticketed';
}
system.debug('==='+lst.applyRatePerContainer);
if(lst.applyRatePerContainer != null)
{
proposedservices.Apply_Rate_Per_Container__c = lst.applyRatePerContainer; //OR
}
if(lst.MASContractLineId != null)
{
proposedservices.MAS_Contract_Line_ID__c = lst.MASContractLineId; //OR
}
proposedservices.Rate__c = lst.extCostAmount;//TODO
proposedservices.Haul_Rate__c = lst.extCostAmount;
proposedservices.Configured__c = true;
if(proposedservices.Service__c != null && proposedservices.Product_Service_Type__c != null && proposedservices.Product_Service_Type__c != '')
{
proposedserviceList.add(proposedservices);
}
}
if(!proposedserviceList.isEmpty())
{
insert proposedserviceList;
system.debug('!!!proposed service list is inserted!!!');
}
}
return proposedserviceList;
}