0

Can any one help me out with this?

Based on the business requirement i need to make a small change in the code .I'm deploying the code but the system throws an error as trigger should have atleast 1%.The test class written show 87% in developer console.

When checked in for the Code Coverage throw "estimate code coverage " in Sandbox --it appears as 53% and when checked in production it shows 23%.I dont know on what based their where triggers or classes written since i have joined recently with the org.

Can i make the change manually in production.The change was (stage name from proposal/price quote to Stage4:proposal delivery).Any Suggestion plz.

@isTest
public class TestCreateSubscriptionOpptyClone1 
{
    static testMethod void test1()
    {
        Account acc1 = new Account(Name='Testing SubscriptionClone', BillingStreet='Banjara hills', BillingCity='Hyd', BillingState='TS',
                                    BillingPostalCode = '500084', BillingCountry = 'India', Phone = '100', Industry = 'Banking',
                                    Type = 'Paid', Customer_Type__c = 'Customer', Customer_List__c = true);
        insert acc1 ;
        contact cc = new contact(FirstName ='Test Contact Subscription', LastName ='Opptyclone', Role__c='Subscription Administrator',AccountId=acc1.Id);
        insert cc;

        Opportunity opty = new Opportunity(Name = 'Test SubscriptionOppty', StageName ='Proposal/Price Quote', Probability =60, 
                                            CloseDate = System.Today(), Type = 'Existing Customer', Assigned_Sales_Engineer__c = null, 
                                            Update_Complete__c = true, Partner__c = 'None', Anchor__c='Non Anchor', AccountId = acc1.Id,
                                            Payment_Type__c = 'Order Form', LeadSource = 'Subscription Renewal');
        insert opty;




        list<OpportunityContactRole> opptyConRolelist1 =  new list<OpportunityContactRole>{
            new OpportunityContactRole(ContactId = cc.Id, OpportunityId = opty.Id, IsPrimary = false, Role = 'Subscription Administrator')
        };   
        insert opptyConRolelist1;

        product2 p2 = new product2(Name ='Postgres Plus Enterprise Edition Unicores', Product_Name1__C='Product - Subscription', Product_Group__c='PPAS',
                                    IsActive = true, Description='Postgres Plus Enterprise Edition Unicores', ARR_Impact1__c = 'Yes');
        insert p2;

        PricebookEntry pbey = new PricebookEntry(Product2ID=p2.id, Pricebook2ID= test.getStandardPricebookId(), UnitPrice=50, isActive=true);
        insert pbey;

        Opportunitylineitem ooli = new Opportunitylineitem(OpportunityId = opty.Id, PricebookEntryId = pbey.Id, Quantity =4, 
                                    Start_Date__c = System.today(), End_Date__c =  System.today() + 100, Type_of_Contract__c='None',
                                    Term__c =12, Type_Of_Product__c='Single Year Subscription', Type_of_ARR__c= 'New Addition ARR',
                                    TotalPrice=1750, No_ARR__c = false, In_Year_Billing__c = 10);
        insert ooli;

        Opportunitylineitem ooli1 = new Opportunitylineitem(OpportunityId = opty.Id, PricebookEntryId = pbey.Id, Quantity =4, 
                                    Start_Date__c = System.today(), End_Date__c =  System.today() + 100, Type_of_Contract__c='None',
                                    Term__c =12, Type_Of_Product__c='Single Year Subscription', Type_of_ARR__c= 'New Addition ARR',
                                    TotalPrice=1750, No_ARR__c = false, In_Year_Billing__c = 10, Parent_Opportunity_Product_Id__c=ooli.Id);
        insert ooli1;

         Contract contr = new Contract(CurrencyIsoCode='USD', Annual_Contract_Value__c =5000, Type_Of_Product__c='Single Year Subscription',
                                        Notes__c='Contract is getting created', Opportunity_Product_Id__c= ooli.Id, Contracts_In_Year_Billing__c=1500,
                                        AccountId=acc1.Id);
        insert contr;

        opty.StageName = 'Closed Won';
        AvoidRecursiveCloning.cloneCreated = false;
        Test.startTest();
        update opty;

        opty.StageName = 'Closed Lost';
        AvoidRecursiveCloning.cloneCreated = false;
        update opty;

        Test.stopTest();
    }
}

How can i deploy the code and test class .Any help very much appreciated.

5
  • When you changed the code, have you updated the relevant test classes as well?
    – highfive
    Feb 25, 2016 at 6:55
  • I am having trouble understanding the question. What sandboxes do you have? What is the overall coverage and the coverage of the specific classes in those sandboxes? Do the test classes have the isTest(SeeAllData=true) Annotation? Feb 25, 2016 at 6:57
  • @highfive,@Sander de Jong,@Richard N:Thanks for your quick response.Previously their was not test class written .So when i made changes in the code and i have written a test class.When i run the test class in Apex test Execution ,the test gets passed and shows the code 87% and overall as 59%.Its a Developer pro sandbox ..unlimited edition .In test class i have not mentioned SeeAllData=true.When i tried deploying ,in production the system throwed an error as Code Coverage Error ..trigger is having 0% ,it should have atleast 1%.Any help very much appreciated. Feb 25, 2016 at 7:16
  • Posting your test class code may help.
    – Richard N
    Feb 25, 2016 at 10:04
  • @RichardN:I have updated the test code. Feb 25, 2016 at 11:06

1 Answer 1

1

You have an open ended issue and have inherited some pretty bad code and practices. We have all been there, Could not add my response as a comment. So writing an answer.

53% coverage is abysmal even for sandbox. Forget about 23%. Sandboxes and production code will have variations in code coverage exp if the test code relies on data in the org(bad idea btw!). Try and fix this coverage as close to 100% as you can. The best practice is not just code coverage but testing the functionality of the application as well. But I guess that ship has sailed.

It looks like for your small code change to be deployed, a related trigger's test code coverage needs to be fixed.

  1. Figure out the related test class for your trigger.
  2. Hopefully it should not be be too hard to update the test class so that you get code coverage on the trigger. Try to get as close to 100% if possible. Create your own test data and use best practices. Look at this for reference. https://developer.salesforce.com/page/How_to_Write_Good_Unit_Tests

  3. DO NOT make any sort of changes manually in production. Test your changes as well and ensure it does not impact any existing functionality.

  4. Once you have updated the test class and tested your changes, the simplest way to migrate the changes to production would be via a changeset. https://help.salesforce.com/apex/HTViewHelpDoc?id=changesets.htm&language=en Hope that piece of test code was the only one with such bad coverage! Good luck!

5
  • 4. For class level, you can not change code directly in production
    – highfive
    Feb 25, 2016 at 8:05
  • @highfive I dint get you?
    – Richard N
    Feb 25, 2016 at 10:04
  • 1
    Sorry, I was talking about 3rd point, apex classes cannot be edited in the production environment directly.
    – highfive
    Feb 25, 2016 at 10:26
  • Yeah, it's impossible to do. Not something you need to warn against.
    – Adrian Larson
    Feb 25, 2016 at 15:02
  • Oh I meant not make any sort of changes such as config etc in production without testing first in sandbox.
    – Richard N
    Feb 25, 2016 at 22:49

You must log in to answer this question.

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