You need to sign in to do that
Don't have an account?
Test class
How to write test class
trigger PitchProductPrice on Pitch_Product__c (After Insert,After Update,before Delete) { //Limit the size of list by using Sets which do not contain duplicate elements set<ID> SQIds = new set<ID>(); set<ID> PTIDs=new set<ID>(); set<string> PFamily=new set<string>(); //When adding new create invoice or updating existing quote if(trigger.isInsert || trigger.isUpdate) { for(Pitch_Product__c p : trigger.new) { SQIds.add(p.Sales_Quote__c); PTIDs.add(p.Product__c); } //Map will contain one quote Id to one Count value(no of Invoice) map<Id,Decimal> SalesQuoteMap = new map<Id,Decimal>(); map<Id,Decimal> SalesQuoteMap1 = new map<Id,Decimal>(); List<Pitch_Product__c> PF=[select id,Product__c ,Product_Family__c from Pitch_Product__c where Sales_Quote__c IN :SQIds AND Product__c IN :PTIDs ]; //use group by to have a single appointment Id with a single sum value for(AggregateResult q : [select Sales_Quote__c,SUM(Total_price__c) from Pitch_Product__c where Sales_Quote__c IN :SQIds group by Sales_Quote__c]) { SalesQuoteMap.put((Id)q.get('Sales_Quote__c'),(Double)q.get('expr0')); } /* for(AggregateResult q : [select Sales_Quote__c,SUM(Discount__c) from Pitch_Product__c where Sales_Quote__c IN :SQIds group by Sales_Quote__c]) { SalesQuoteMap1.put((Id)q.get('Sales_Quote__c'),(Double)q.get('expr0')); }*/ List<gii__SalesQuote__c> SalesQuoteToUpdate = new List<gii__SalesQuote__c>(); //Run the for loop on Sales Quote using the non-duplicate set of Sales quote Ids for(gii__SalesQuote__c o : [Select Id,Credit_Adjustments__c, Product_Cost__c from gii__SalesQuote__c where Id IN :SQIds]) { Double QuoteCount = SalesQuoteMap.get(o.Id); //Double Discount = SalesQuoteMap1.get(o.Id); //o.Credit_Adjustments__c= Discount; o.Product_Cost__c=QuoteCount ; SalesQuoteToUpdate.add(o); } update SalesQuoteToUpdate; } //When deleting created quote if(trigger.isDelete) { for(Pitch_Product__c p : trigger.old) { SQIds.add(p.Sales_Quote__c); system.debug('Quote id'+SQIds); PFamily.add(p.Name); } //Map will contain one appointment Id to one Count value(no of Invoice) map<Id,Decimal> SalesQuoteMap = new map<Id,Decimal>(); //map<Id,Decimal> SalesQuoteMap1 = new map<Id,Decimal>(); List<Pitch_Product__c> PF=[select id,Name,Sales_Quote__c ,Product_Family__c from Pitch_Product__c where Sales_Quote__c IN :SQIds AND Name=:PFamily]; //use group by to have a single Quote Id with a single sum value if(PF.size()>0) { for(AggregateResult q : [select Sales_Quote__c,SUM(Total_price__c),SUM(Discount__c) from Pitch_Product__c where Name=:PFamily AND Sales_Quote__c IN :SQIds group by Sales_Quote__c]) { SalesQuoteMap.put((Id)q.get('Sales_Quote__c'),(Double)q.get('expr0')); } /*for(AggregateResult q : [select Sales_Quote__c,SUM(Discount__c) from Pitch_Product__c where Name=:PFamily AND Sales_Quote__c IN :SQIds group by Sales_Quote__c]) { SalesQuoteMap1.put((Id)q.get('Sales_Quote__c'),(Double)q.get('expr0')); }*/ List<gii__SalesQuote__c> SalesQuoteToUpdate = new List<gii__SalesQuote__c>(); //Run the for loop on sales quote using the non-duplicate set of Quote Ids for(gii__SalesQuote__c o : [Select Id, Credit_Adjustments__c,Product_Cost__c from gii__SalesQuote__c where Id IN :SQIds]) { Double QuoteCount = SalesQuoteMap.get(o.Id); //Double Discount = SalesQuoteMap1.get(o.Id); //o.Credit_Adjustments__c= o.Credit_Adjustments__c-Discount; o.Product_Cost__c=o.Product_Cost__c- QuoteCount; SalesQuoteToUpdate.add(o); } update SalesQuoteToUpdate; } } }
Please help me to write test class for this trigger.
Thank you. |