• Jithin U Nair
  • NEWBIE
  • 30 Points
  • Member since 2019
  • Sr. Developer

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 5
    Replies
I'm a newbie for APEX and I'm trying to redeploy a fix for a former APEX trigger we had already deployed to production.  When I try to deploy it, I get it shows Code Coverage as 64% (9/14) and won't let me deploy.  Can someone please let me know what I'm doing wrong?

Apex Trigger:
trigger UpdatePricing on OpportunityLineItem (before insert, before update) {


Map<String, List<Volume_Discount__c>> PricingMap = new Map<String, List<Volume_Discount__c>>();
for(Volume_Discount__c  P : [SELECT ID,Minimum_Quantity__c,Product__c,Price_Book__c  FROM Volume_Discount__c ORDER BY Minimum_Quantity__c])
{
  if(PricingMap.KeySet().contains(P.Product__c+'|'+P.Price_Book__c))
  {   
     PricingMap.get(P.Product__c+'|'+P.Price_Book__c).add(P);
  }
  else
  {
     PricingMap.put(P.Product__c+'|'+P.Price_Book__c,new List<Volume_Discount__c> {P});
  }
}


for(OpportunityLineItem  oli : Trigger.new)
{
oli.Volume_Discount__c = null;
if(PricingMap.KeySet().contains(oli.Product2Id+'|'+oli.Opportuity_PriceBook2__c) && oli.ProductAndPriceBookActive__c)
{
    for(Volume_Discount__c P : PricingMap.get(oli.Product2Id+'|'+oli.Opportuity_PriceBook2__c))
    {
        if(oli.quantity >= P.Minimum_Quantity__c)
        {
           oli.Volume_Discount__c = P.ID;
        }
    }
}

}


}

Apex Class:
@isTest
Public class UpdatePricingTest{


Public static testmethod void testing(){
integer def = 0;
list<OpportunityLineitem  > olitoupdate = new list<OpportunityLineitem  >();
for(OpportunityLineitem  oli : [SELECT ID,Quantity from OpportunityLineItem  order by createddate desc LIMIT 5]){
OLI.Quantity = def +200;
olitoupdate.add(OLI);
}
if(olitoupdate.size()>0){
update olitoupdate;
}


PriceBook2 PB = new PriceBook2();
PB.Name = 'New Pricebook';
PB.isactive = true;
insert PB;

Product2 pro = new Product2();
pro.Name = 'Prod';
pro.Billing_Type__c = 'Financed';
insert pro;


insert new PriceBookEntry(Product2Id=pro.Id, Pricebook2Id=Test.getStandardPricebookId(), UnitPrice=0);


PricebookEntry  PBE = new PricebookEntry();
PBE.Product2ID = Pro.ID;
PBE.PriceBook2ID = PB.ID;
PBE.UnitPrice = 120;
PBE.Isactive = true;
insert PBE;


Volume_Discount__c Pricing = new Volume_Discount__c();
Pricing.Minimum_Quantity__c = 100;
Pricing.Product__c = Pro.ID;
Pricing.Price_Book__c  = PB.ID;
Pricing.Annual_Overage__c = 2.5;
Pricing.Annual_Price__c = 2.5;
Pricing.Quarterly_Overage__c = 2.5;
Pricing.Quarterly_Price__c = 2.5;
Pricing.Monthly_Overage__c = 2.5;
Pricing.Monthly_Price__c = 2.5;
insert Pricing;

Account acc = new Account(Name = 'Test Account1');
acc.BillingState = 'TX';
acc.AccountSource = 'Inbound Call';
acc.Industry = 'Bank';
insert acc;

Opportunity Opp = new Opportunity();
Opp.Name = 'Test Opp';
Opp.StageName = 'Interview';
Opp.PriceBook2ID = PB.ID;
Opp.CloseDate = Date.TODAY()-10;
Opp.AccountID = acc.ID;
Opp.Testing__c = true;
insert Opp;

OpportunityLineItem OLI = new OpportunityLineItem();
OLI.OpportunityID = Opp.ID;
OLI.PriceBookEntryID = PBE.ID;
OLI.Quantity = 100;
OLI.Volume_Discount__c = Pricing.ID;
insert OLI;

OLI.Quantity = 99;
update OLI;

}

}

 
I am trying to create a quick Action that calls the flow and lightning component to create a record as suggested in the blog (https://thewizardnews.com/2018/08/02/url-hack-functionality-lightning/) here. I need to create a record of custom object from Opportunity record , using the Quick action as suggested in the blog. I created a flow like below with the Action which calls the lightning component createAXProjectRecords 
User-added image
And the Lightning component is like
createAXProjectRecords.cmp
<aura:component implements="lightning:availableForFlowActions"> <aura:attribute name="InputContactID" type="String" /> <aura:attribute name="InputAccountID" type="String" /> </aura:component>
createAXProjectRecords.design
<design:component> <design:attribute name="InputContactID" /> <design:attribute name="InputAccountID" /> </design:component>
createAXProjectRecordsController.js
({ invoke : function(component, event, helper){ var ContactID = component.get("v.InputContactID"); var AccountID = component.get("v.InputAccountID"); var createRecordEvent = $A.get("e.force:createRecord"); createRecordEvent.setParams({ "entityApiName": "AX_Project__c", "defaultFieldValues": { 'Contact__c' : ContactID, 'Account__c': AccountID } }); createRecordEvent.fire(); } })
When I try to click on the Quick Action on the Opportunity record I get  
User-added image
Can anyone please suggest me what I am missing here.
  • January 08, 2020
  • Like
  • 0
I'm a newbie for APEX and I'm trying to redeploy a fix for a former APEX trigger we had already deployed to production.  When I try to deploy it, I get it shows Code Coverage as 64% (9/14) and won't let me deploy.  Can someone please let me know what I'm doing wrong?

Apex Trigger:
trigger UpdatePricing on OpportunityLineItem (before insert, before update) {


Map<String, List<Volume_Discount__c>> PricingMap = new Map<String, List<Volume_Discount__c>>();
for(Volume_Discount__c  P : [SELECT ID,Minimum_Quantity__c,Product__c,Price_Book__c  FROM Volume_Discount__c ORDER BY Minimum_Quantity__c])
{
  if(PricingMap.KeySet().contains(P.Product__c+'|'+P.Price_Book__c))
  {   
     PricingMap.get(P.Product__c+'|'+P.Price_Book__c).add(P);
  }
  else
  {
     PricingMap.put(P.Product__c+'|'+P.Price_Book__c,new List<Volume_Discount__c> {P});
  }
}


for(OpportunityLineItem  oli : Trigger.new)
{
oli.Volume_Discount__c = null;
if(PricingMap.KeySet().contains(oli.Product2Id+'|'+oli.Opportuity_PriceBook2__c) && oli.ProductAndPriceBookActive__c)
{
    for(Volume_Discount__c P : PricingMap.get(oli.Product2Id+'|'+oli.Opportuity_PriceBook2__c))
    {
        if(oli.quantity >= P.Minimum_Quantity__c)
        {
           oli.Volume_Discount__c = P.ID;
        }
    }
}

}


}

Apex Class:
@isTest
Public class UpdatePricingTest{


Public static testmethod void testing(){
integer def = 0;
list<OpportunityLineitem  > olitoupdate = new list<OpportunityLineitem  >();
for(OpportunityLineitem  oli : [SELECT ID,Quantity from OpportunityLineItem  order by createddate desc LIMIT 5]){
OLI.Quantity = def +200;
olitoupdate.add(OLI);
}
if(olitoupdate.size()>0){
update olitoupdate;
}


PriceBook2 PB = new PriceBook2();
PB.Name = 'New Pricebook';
PB.isactive = true;
insert PB;

Product2 pro = new Product2();
pro.Name = 'Prod';
pro.Billing_Type__c = 'Financed';
insert pro;


insert new PriceBookEntry(Product2Id=pro.Id, Pricebook2Id=Test.getStandardPricebookId(), UnitPrice=0);


PricebookEntry  PBE = new PricebookEntry();
PBE.Product2ID = Pro.ID;
PBE.PriceBook2ID = PB.ID;
PBE.UnitPrice = 120;
PBE.Isactive = true;
insert PBE;


Volume_Discount__c Pricing = new Volume_Discount__c();
Pricing.Minimum_Quantity__c = 100;
Pricing.Product__c = Pro.ID;
Pricing.Price_Book__c  = PB.ID;
Pricing.Annual_Overage__c = 2.5;
Pricing.Annual_Price__c = 2.5;
Pricing.Quarterly_Overage__c = 2.5;
Pricing.Quarterly_Price__c = 2.5;
Pricing.Monthly_Overage__c = 2.5;
Pricing.Monthly_Price__c = 2.5;
insert Pricing;

Account acc = new Account(Name = 'Test Account1');
acc.BillingState = 'TX';
acc.AccountSource = 'Inbound Call';
acc.Industry = 'Bank';
insert acc;

Opportunity Opp = new Opportunity();
Opp.Name = 'Test Opp';
Opp.StageName = 'Interview';
Opp.PriceBook2ID = PB.ID;
Opp.CloseDate = Date.TODAY()-10;
Opp.AccountID = acc.ID;
Opp.Testing__c = true;
insert Opp;

OpportunityLineItem OLI = new OpportunityLineItem();
OLI.OpportunityID = Opp.ID;
OLI.PriceBookEntryID = PBE.ID;
OLI.Quantity = 100;
OLI.Volume_Discount__c = Pricing.ID;
insert OLI;

OLI.Quantity = 99;
update OLI;

}

}