-4
trigger HandleProductPriceChange on Merchandies__c (after update) {

   List<Line_Item__c> openLineItems =[SELECT j.Unit_Price__c, j.Merchandise__r.Price__c
   FROM Line_Item__c j
   WHERE j.Invoice_Statement__r.Status__c = 'Negotiating'
   AND j.Merchandise__r.id IN :Trigger.new
   FOR UPDATE];

   for (Line_Item__c li: openLineItems) {
      if ( li.Merchandise__r.Price__c < li.Unit_Price__c ){
          li.Unit_Price__c = li.Merchandise__r.Price__c;
      }
   }
   update openLineItems;
}

I wrote following test Class but code coverage is not 100%:-

@isTest
public class TestProductPriceChange {
    Static TestMethod void TestPrice(){
     Merchandies__c mer = new Merchandies__c();
        mer.Name= 'Pept';
        mer.Description__c = 'Scooty of 125 cc';
        mer.Price__c = 600;
        mer.Total_Inventory__c = 100;
     insert mer;

        Invoice_Statement__c invoice = new Invoice_Statement__c();
           invoice.Status__c = 'Negotiating';
           invoice.Description__c = 'pept';
         insert invoice;

        Line_Item__c line = new Line_Item__c(
           Name = '1',
           Unit_Price__c = 700,
           Merchandise__c = mer.id, 
           Invoice_Statement__c = invoice.Id);
        insert line;


    }

}
2
  • post the code which you tried for test class code as we can suggest better ways to find solution
    – sfdev
    Aug 25, 2015 at 10:05
  • 1
    Hi Sandesh, what exactly is not clear to you about writing test methods for that trigger ? Getting answers is easiest if you explain us what your real question is. Example: what you do not understand. Aug 25, 2015 at 10:12

1 Answer 1

0

Your trigger fires only on "update" and I can't see any update DML statement in your test class. Try below

@isTest public class TestProductPriceChange { 

    Static TestMethod void TestPrice(){ 
    Merchandies__c mer = new Merchandies__c(); 
    mer.Name= 'Pept'; 
    mer.Description__c = 'Scooty of 125 cc'; 
    mer.Price__c = 600; 
    mer.Total_Inventory__c = 100; 
    insert mer;

        Invoice_Statement__c invoice = new Invoice_Statement__c();
           invoice.Status__c = 'Negotiating';
           invoice.Description__c = 'pept';
         insert invoice;

        Line_Item__c line = new Line_Item__c(
           Name = '1',
           Unit_Price__c = 700,
           Merchandise__c = mer.id, 
           Invoice_Statement__c = invoice.Id);
        insert line;

//Update mer

update mer;

    }

    }
1
  • @SandeshGanjare: Could you please mark it as your answer if it solved your issue?
    – Prakash
    Aug 25, 2015 at 11:28

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .