I have copied the code from the blog amitsalesforce for syncing custom fields from Opportunity Line Item to Quote Line Item on creation of Quote.
Made small changes in that code and that works fine for me. But when it comes to test class I get only code coverage of 70%. Below is the test class
@isTest
public with sharing class testTriggerOLISyncQLI{
static testMethod void myUnitTriggerOLISyncQLI(){
Account a = new Account(Name = 'Camphell');
a.AccountNumber = '2345';
a.SAP_SYNCED__c = true;
a.BillingStreet = 'Oliver Mart st';
a.BillingCity = 'Tasborn';
a.BillingState = 'Newyork';
a.BillingCountry = 'US';
insert a;
Account_Sales_Area__c ASA = new Account_Sales_Area__c();
ASA.SAP_ACC_ID__c = a.id;
ASA.SAP_VKORG__c = '3000';
ASA.SAP_VTWEG__c = '10';
ASA.SAP_SPART__c = '00';
ASA.SAP_INCO1__c = 'FOF';
ASA.SAP_INCO2__c = 'Sample';
ASA.SAP_ZTERM__c = 'Rs';
ASA.SAP_PARVW__c = 'SHIP';
insert ASA;
PriceBook2 PB = new PriceBook2();
PB.Name = 'Standard';
PB.Condition_Type__c = 'SLG1';
insert PB;
Product2 p = new product2(name='unittest');
p.Family = 'License';
p.SAP_MATNR__c = 'M-003';
p.ProductCode = 'M-003';
p.isActive = true;
p.SAP_SYNCED__c = true;
insert p;
Customer_Material_Info__c CMI = new Customer_Material_Info__c();
CMI.SAP_ACC_ID__c = a.id;
CMI.SAP_PROD_ID__c = p.id;
CMI.SAP_KDMAT__c = '4325';
CMI.SAP_POSTX__c = 'CMI test Product';
insert CMI;
//Pricebook2 stdPb = [select Id from Pricebook2 where isStandard=true limit 1];
Id pricebookId = Test.getStandardPricebookId();
PricebookEntry pbe = new PricebookEntry(pricebook2id = pricebookId ,
product2id = p.id,
unitprice=40.0,
isActive=true);
insert pbe;
Date myDate = Date.newInstance(2014, 10, 01);
Opportunity opp = new Opportunity(Name ='Camphell Opp');
opp.AccountId = a.id;
opp.StageName = 'Sample Request';
opp.CloseDate = myDate ;
opp.PriceBook2Id = pricebookId ;
insert opp;
System.debug('Oppprice>>>' +opp.PriceBook2Id);
List<OpportunityLineItem >oli = new List <OpportunityLineItem >();
oli.add( new OpportunityLineItem(PricebookEntryId=pbe.Id,
OpportunityId=opp.Id,
Quantity=10,
Customer_Material_Number__c = '6745',
Distribution_Channel__c = '10',
Division__c = '00',
Sales_Org__c = '3000',
SAP_Customer_Price__c = 35,
TotalPrice=100));
oli.add( new OpportunityLineItem(PricebookEntryId=pbe.Id,
OpportunityId=opp.Id,
Quantity=9,
Customer_Material_Number__c = '6790',
Distribution_Channel__c = '111',
Division__c = '01',
Sales_Org__c = '3500',
SAP_Customer_Price__c = 37,
TotalPrice=100));
insert oli;
Quote q = new Quote(Name = 'Camphell Quote');
q.OpportunityId = opp.id;
q.PriceBook2Id = pricebookId ;
insert q;
List<QuoteLineItem > qli = new List<QuoteLineItem > ();
qli.add( new QuoteLineItem(pricebookentryid =pbe.Id,
QuoteId=q.Id,
Quantity=10,
unitprice=123,
Distribution_Channel__c = '10',
Division__c = '00',
Sales_Org__c = '3000',
SAP_Customer_Price__c = 37
));
qli.add( new QuoteLineItem(pricebookentryid =pbe.Id,
QuoteId=q.Id,
Quantity=10,
unitprice=111,
Distribution_Channel__c = '11',
Division__c = '01',
Sales_Org__c = '3001',
SAP_Customer_Price__c = 35
));
insert qli;
}
}
The code didnt cover this part
Where am I missing ?? Suggestion please.