function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Tim Teague 4Tim Teague 4 

Cannot deploy a change set to make an APEX trigger inactive

I am not a dev but I need to disable an apex trigger.  I've made it inactive in Sandbox but can not deploy in production. 

I have tried to deploy with its specific test class but the error I get is the following:

AccountUtilityTestClassvalidateTotalRollupRevenueFieldsSystem.DmlException: Upsert failed. First exception on row 0 with id 0060X00000WHqdCQAT; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, updatecontactrolecount: execution of BeforeUpdate caused by: System.LimitException: Too many SOQL queries: 101 Trigger.updatecontactrolecount: line 22, column 1: [] 
Stack Trace: Class.AccountUtilityTestClass.validateTotalRollupRevenueFields: line 80, column 1


Here is the Test Class

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
@isTest(SeeAllData=true)

private class AccountUtilityTestClass {
  
  static testMethod void validateTotalRollupRevenueFields() {
 
    Account TA1 = new Account(
      Name='Testaccount1',
      Region__c='EMEA',
      CurrencyIsoCode='GBP'           
    );
    upsert TA1;
     
    Account TA2 = new Account(
      Name='Testaccount2',
      Region__c='APAC',
      CurrencyIsoCode='USD',
      ParentId=TA1.Id          
    );
    upsert TA2;
    Opportunity TO2 = new Opportunity(
      Name='TestOpportunity2',
      Pricebook2Id=Test.getStandardPricebookId(),
      AccountId=TA2.Id,
      CurrencyIsoCode='USD',
      StageName='Closed Won',
      CloseDate=Date.today()
    );
    upsert TO2;
    Quote TQ2 = new Quote(
      OpportunityId=TO2.Id,
      Pricebook2Id=Test.getStandardPricebookId(),
      Name='Testquote2'
    );
    upsert TQ2;
    QuoteLineItem TQL2 = new QuoteLineItem(
      QuoteId=TQ2.Id,
      PricebookEntryId='01ub000000kbxgd',
      Quantity=1,
      Product2Id='01tb00000036P54',
      UnitPrice=Math.random()*1000,
      Partner_Revenue__c=Math.random()*1000
    );
    upsert TQL2;
    TO2.SyncedQuoteId = TQ2.Id;
    upsert TO2;

    Account TA3 = new Account(
      Name='Testaccount3',
      Region__c='APAC',
      CurrencyIsoCode='USD',
      ParentId=TA2.Id          
    );
    upsert TA3;
    Opportunity TO3 = new Opportunity(
      Name='TestOpportunity3',
      Pricebook2Id=Test.getStandardPricebookId(),
      AccountId=TA3.Id,
      CurrencyIsoCode='USD',
      StageName='Closed Won',
      CloseDate=Date.today()
    );
    upsert TO3;
    Quote TQ3 = new Quote(
      OpportunityId=TO3.Id,
      Pricebook2Id=Test.getStandardPricebookId(),
      Name='Testquote3'
    );
    upsert TQ3;
    QuoteLineItem TQL3 = new QuoteLineItem(
      QuoteId=TQ3.Id,
      PricebookEntryId='01ub000000kbxgd',
      Quantity=1,
      Product2Id='01tb00000036P54',
      UnitPrice=Math.random()*1000,
      Partner_Revenue__c=Math.random()*1000
    );
    upsert TQL3;
    TO3.SyncedQuoteId = TQ3.Id;
    upsert TO3;
     
    System.debug([SELECT Name, Total_Zappi_Revenue__c, Amount FROM Opportunity WHERE AccountId =: TA1.Id]);
    System.debug([SELECT Name, Total_Zappi_Revenue__c, Amount FROM Opportunity WHERE AccountId =: TA2.Id]);
    System.debug([SELECT Name, Total_Zappi_Revenue__c, Amount FROM Opportunity WHERE AccountId =: TA3.Id]);
     
  }

}


Any advice on this is really appreciated!!!!
v varaprasadv varaprasad
Hi Tim,

Change your code like below and check once ,And use insert instead of upsert if you are inserting new record.
 
private class AccountUtilityTestClass {
  
  static testMethod void validateTotalRollupRevenueFields() {
 Test.startTest();
    Account TA1 = new Account(
      Name='Testaccount1',
      Region__c='EMEA',
      CurrencyIsoCode='GBP'           
    );
    upsert TA1;
     
    Account TA2 = new Account(
      Name='Testaccount2',
      Region__c='APAC',
      CurrencyIsoCode='USD',
      ParentId=TA1.Id          
    );
    upsert TA2;
    Opportunity TO2 = new Opportunity(
      Name='TestOpportunity2',
      Pricebook2Id=Test.getStandardPricebookId(),
      AccountId=TA2.Id,
      CurrencyIsoCode='USD',
      StageName='Closed Won',
      CloseDate=Date.today()
    );
    upsert TO2;
    Quote TQ2 = new Quote(
      OpportunityId=TO2.Id,
      Pricebook2Id=Test.getStandardPricebookId(),
      Name='Testquote2'
    );
    upsert TQ2;
    QuoteLineItem TQL2 = new QuoteLineItem(
      QuoteId=TQ2.Id,
      PricebookEntryId='01ub000000kbxgd',
      Quantity=1,
      Product2Id='01tb00000036P54',
      UnitPrice=Math.random()*1000,
      Partner_Revenue__c=Math.random()*1000
    );
    upsert TQL2;
    TO2.SyncedQuoteId = TQ2.Id;
    upsert TO2;

    Account TA3 = new Account(
      Name='Testaccount3',
      Region__c='APAC',
      CurrencyIsoCode='USD',
      ParentId=TA2.Id          
    );
    upsert TA3;
    Opportunity TO3 = new Opportunity(
      Name='TestOpportunity3',
      Pricebook2Id=Test.getStandardPricebookId(),
      AccountId=TA3.Id,
      CurrencyIsoCode='USD',
      StageName='Closed Won',
      CloseDate=Date.today()
    );
    upsert TO3;
    Quote TQ3 = new Quote(
      OpportunityId=TO3.Id,
      Pricebook2Id=Test.getStandardPricebookId(),
      Name='Testquote3'
    );
    upsert TQ3;
    QuoteLineItem TQL3 = new QuoteLineItem(
      QuoteId=TQ3.Id,
      PricebookEntryId='01ub000000kbxgd',
      Quantity=1,
      Product2Id='01tb00000036P54',
      UnitPrice=Math.random()*1000,
      Partner_Revenue__c=Math.random()*1000
    );
    upsert TQL3;
    TO3.SyncedQuoteId = TQ3.Id;
    upsert TO3;
    Test.stopTest();     
    
     
  }

}

Please follow below salesforce Best Practice for Test Classes :-

1. Test class must start with @isTest annotation if class class version is more than 25
2. Test environment support @testVisible , @testSetUp as well
3. Unit test is to test particular piece of code working properly or not .
4. Unit test method takes no argument ,commit no data to database ,send no email ,flagged with testMethod keyword .
5. To deploy to production at-least 75% code coverage is required
6. System.debug statement are not counted as a part of apex code limit.
7. Test method and test classes are not counted as a part of code limit
9. We should not focus on the  percentage of code coverage ,we should make sure that every use case should covered including positive, negative,bulk and single record .
Single Action -To verify that the the single record produces the correct an expected result .
Bulk action -Any apex record trigger ,class or extension must be invoked for 1-200 records .
Positive behavior : Test every expected behavior occurs through every expected permutation , i,e user filled out every correctly data and not go past the limit .
Negative Testcase :-Not to add future date , Not to specify negative amount.
Restricted User :-Test whether a user with restricted access used in your code .
10. Test class should be annotated with @isTest .
11 . @isTest annotation with test method  is equivalent to testMethod keyword .
12. Test method should static and no void return type .
13. Test class and method default access is private ,no matter to add access specifier .
14. classes with @isTest annotation can't be a interface or enum .
15. Test method code can't be invoked by non test request .
16. Stating with salesforce API 28.0 test method can not reside inside non test classes .
17. @Testvisible annotation to make visible private methods inside test classes.
18. Test method can not be used to test web-service call out . Please use call out mock .
19. You can't  send email from test method.
20.User, profile, organization, AsyncApexjob, Corntrigger, RecordType, ApexClass, ApexComponent ,ApexPage we can access without (seeAllData=true) .
21. SeeAllData=true will not work for API 23 version eailer .
22. Accessing static resource test records in test class e,g List<Account> accList=Test.loadData(Account,SobjectType,'ResourceName').
23. Create TestFactory class with @isTest annotation to exclude from organization code size limit .
24. @testSetup to create test records once in a method  and use in every test method in the test class .
25. We can run unit test by using Salesforce Standard UI,Force.com IDE ,Console ,API.
26. Maximum number of test classes run per 24 hour of period is  not grater of 500 or 10 multiplication of test classes of your organization.
27. As apex runs in system mode so the permission and record sharing are not taken into account . So we need to use system.runAs to enforce record sharing .
28. System.runAs will not enforce user permission or field level permission .
29. Every test to runAs count against the total number of DML issued in the process .


Hope this helps you!
If my answer helps resolve your query, please mark it as the 'Best Answer' & upvote it to benefit others.

Thanks
Varaprasad
@For  Support: varaprasad4sfdc@gmail.com
 
Tim Teague 4Tim Teague 4
I still can't deploy 

I added the inactive trigger and the new test class to the changeset. But it's not working 


Class NameMethod NameError MessageAccountUtilityTestClassvalidateTotalRollupRevenueFieldsSystem.DmlException: Upsert failed. First exception on row 0 with id 0060X00000WHxEDQA1; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, updatecontactrolecount: execution of BeforeUpdate caused by: System.LimitException: Too many SOQL queries: 101 Trigger.updatecontactrolecount: line 22, column 1: [] 
Stack Trace: Class.AccountUtilityTestClass.validateTotalRollupRevenueFields: line 80, column 1
User-added image