You need to sign in to do that
Don't have an account?
Cubs 42
i broke my salesforce. need 1% code coverage on this trigger quickly and i dont know where to start
i broke my salesforce. need 1% code coverage on this trigger quickly and i dont know where to start
my trigger
my trigger
/* * @description Trigger for OpportunityLineItem - this trigger has no test class * @author Tristan Harley * @date 9.MAR.2017 */ trigger OpportunityLineItemsTrigger on OpportunityLineItem (before insert, before update) { //create list of related object ids Set<string> setOppId = new Set<String>(); Set<string> setProdId = new Set<String>(); //Populate the lists related object ids to the OpportunityLineItem for( OpportunityLineItem opli : trigger.New ) { setOppId.add(opli.opportunityid); setProdId.add(opli.product2id); } //Check if related object ids are populated if( setOppId.size() > 0 && setProdId.size() > 0) { //Map the related object from the lists Map<Id,Opportunity> mapOpp = new Map<Id,Opportunity> ([select id ,Licensed_Months__c from Opportunity where id in :setOppId ] ); Map<Id,Product2> mapProd = new Map<Id,Product2> ([select id ,e3_Product_License__c ,Partners_Share__c from Product2 where id in :setProdId] ); //loop through the OpportunityLineItem that where trigged for( OpportunityLineItem opli : trigger.New ) { //Set Defalts on the OpportunityLineItem that where trigged if(Trigger.isInsert) { opli.Discount = 0; } //check if there is a opportunity related to the OpportunityLineItem if(Trigger.isInsert) { if(mapOpp.containsKey(opli.opportunityid) ) { //Match the related record Opportunity opp = mapOpp.get(opli.opportunityid); //Set fields on the OpportunityLineItem that where trigged System.debug('----------->'+opp.Licensed_Months__c); opli.Licensed_Months__c = opp.Licensed_Months__c; } } //check if there is a product related to the OpportunityLineItem if(Trigger.isInsert) { if(mapProd.containsKey(opli.product2id) ) { //Match the related record Product2 prod = mapProd.get(opli.product2id); //Set fields on the OpportunityLineItem that where trigged System.debug('----------->'+prod.e3_Product_License__c); opli.e3_Product_Licensing__c = prod.e3_Product_License__c; System.debug('----------->'+prod.Partners_Share__c ); opli.Partners_Share__c = prod.Partners_Share__c ; } } } } }
Hi Cubs,
Please create apex class NAMED: (OpportunityLineItemsTrigger_Test)
And Paste this code
It cover your trigger code.
Marks as a best if it helps you.
Regards,
Suraj
All Answers
Hi Cubs,
Please create apex class NAMED: (OpportunityLineItemsTrigger_Test)
And Paste this code
It cover your trigger code.
Marks as a best if it helps you.
Regards,
Suraj
i really need to learn to make test classes.
haha
thanks so much
tristan
thanks again this was duplicated and customised again to solve a new problem