You need to sign in to do that
Don't have an account?
Test class
Hi All
Can you please help me to write a test calss for the following code.
private void createOrderASOCs(Id orderId, Id accountId, QuoteLine__c[] orderASOCs){
System.debug('In createOrderASOCs() Function');
//******************** ASOCs ********************
List<ASOCs__c> insertASOC = new List<ASOCs__c>();
List<Maintenance_Plan__c> insertMaint =new List<Maintenance_Plan__c>();
for(QuoteLine__c asoc:orderASOCs){
System.debug('Looping Lines (ASOCS)');
String tnId;
Double currQTY=asoc.Quantity__c;
if(asoc.Quote_Telephone_Number_Config__r!=null&&asoc.Quote_Telephone_Number_Config__r.size()>0){
System.debug('Adding TN Level ASOCS');
for(QuoteTelephoneNumberConfig__c orderTNs:asoc.Quote_Telephone_Number_Config__r){
tnId = tnMap.get(orderTNs.QuoteTelephoneNumber__r.Name);
System.debug(' Current TN ID:'+tnId);
insertASOC.addAll(buildTNAsocs(tnId, orderId, asoc,1));
currQTY -=1;
}
}
//********* Working with the Main BTN *********
if(currQTY>0){
System.debug('Adding BTN Level ASOCS');
tnId = tnMap.get(mainBTN);
System.debug(' Current BTN Id:'+ tnId);
insertASOC.addAll(buildTNAsocs(tnId, orderId, asoc,currQTY));
}
//Maintenance Plan
if(asoc.MasterProduct__r!=null&&asoc.MasterProduct__r.QuantityType__c=='Maintenance Plan'){
System.debug('Creating Maintenance Plan');
Maintenance_Plan__c maintPlan = new Maintenance_Plan__c();
maintPlan.Account__c = accountId;
maintPlan.Order__c = orderId;
maintPlan.Maintenance_Plan_Type__c = asoc.MasterProduct__r.Name;
maintPlan.Monthly_Maintenance_Rate__c = asoc.Price__c;
maintPlan.Contract_Term__c = asoc.Term__c;
maintPlan.Contract_Start_Date__c = asoc.Quote__r.Contract_Start_Date__c;
insertMaint.add(maintPlan);
}
}
//PIC/IPIC
if(otherASOCS!=null&&otherASOCS.size()>0){
System.debug('Adding PIC and IPIC');
for(ASOCs__c tmpASOC:otherASOCS){
tmpASOC.Order__c=orderId;
tmpASOC.Telephone_Number__c=tnMap.get(mainBTN);
insertASOC.add(tmpASOC);
}
}
if(insertASOC!=null&&insertASOC.size()>0){
System.debug('Inserting ASOCS');
insert insertASOC;
}
//insert Maint Plan objects.
if(insertMaint!=null&&insertMaint.size()>0){
System.debug('Inserting Maint');
insert insertMaint;
}
}
private ASOCs__c[] buildTNAsocs(Id tnId, Id orderId, QuoteLine__c asoc, Double qty){
List<ASOCs__c> tnASOCs = new List<ASOCs__c>();
ASOCs__c orderASOC = new ASOCs__c();
orderASOC.Telephone_Number__c=tnId;
orderASOC.Order__c=orderId;
if(asoc.Product__r!=null){
orderASOC.Asoc__c=asoc.Product__r.Name;
System.debug(' ASOC Name:'+ asoc.Product__r.Name);
orderASOC.ASOC_Description__c=asoc.Product__r.Description;
}else{
System.debug(' ASOC has Null Product');
orderASOC.Asoc__c=asoc.CustomAsoc__c;
System.debug(' ASOC Name:'+ asoc.CustomAsoc__c);
orderASOC.ASOC_Description__c=asoc.CustomDescription__c;
}
orderASOC.Rate__c=asoc.Price__c;
orderASOC.Quantity__c=qty;
orderASOC.Magnys_Service_Code_Desc__c=asoc.Magnys_Service_Code_Desc__c;
tnASOCs.add(orderASOC);
//Check for BOM Items
System.debug('ASOC BOM Items');
if(asoc.Quote_Line_BOM_Items__r!=null&&asoc.Quote_Line_BOM_Items__r.size()>0){
QuoteLineBomItem__c[] tmpBMs = asoc.Quote_Line_BOM_Items__r;
for(QuoteLineBomItem__c bom:tmpBMs){
System.debug('Looping BOM Items');
ASOCs__c bomASOC = new ASOCs__c();
bomASOC.Telephone_Number__c=tnId;
bomASOC.Order__c=orderId;
if(bom.Product__r!=null){
bomASOC.Asoc__c=bom.Product__r.Name;
bomASOC.ASOC_Description__c=bom.Product__r.Description;
}else{
System.debug('ASOC has Null Product');
}
bomASOC.Rate__c=0.0;
bomASOC.Quantity__c=bom.Quantity__c;
bomASOC.Magnys_Service_Code_Desc__c=asoc.Magnys_Service_Code_Desc__c;
tnASOCs.add(bomASOC);
}
}
return tnASOCs;
}
I can't write the test class for you, but I do have a few comments: