• Dean Blanch
  • NEWBIE
  • 10 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 9
    Replies
THE CODE USED

trigger  NumberOfContacts on Contact (after insert) {
set<id> setid = new set<id>();

list<account> listaccount = new list<account>();
for(contact con : trigger.new){

setid.add(con.accountid);
}

For(account acc : [select id,name,Number_of_Contacts__c, (select id from contacts)from account where id=:setid]) {
Account ac1 = new account();

ac1.id=acc.id;

ac1.Number_of_Contacts__c= acc.contacts.size();

listaccount.add(ac1);
}

The ITEST CODE

@istest
02public class testnumberofcontacts {
03    @istest static void checknumbers(){
04        test.starttest();
05        account testaccount = new account(name = 'Test account');
06        insert testaccount;
07        contact testcontact = new contact(lastname = 'Samplename', accountid = testaccount.Id);
08        insert testcontact;
09        test.stopTest();
10        list<account> queriedaccount = [select name, number_of_contacts__C from account where id =: testaccount.Id];
11        decimal resultcount;
12        for(account a: queriedaccount){
13            resultcount = a.Number_of_contacts__c;
14        }
15        system.assertEquals(1, resultcount);
16    }
17 
18}

THE 7! FAILURES

CMBatchCampaignStatsTesttest_LinkedCampaignsSystem.AssertException: Assertion Failed: Expected: 25, Actual: null 
Stack Trace: Class.wbsendit.CMBatchCampaignStatsTest.test_LinkedCampaigns: line 58, column 1
CMBatchCampaignStatsTesttest_LinkedCampaigns_doRun_UpdateOnSystem.AssertException: Assertion Failed: Expected: 25, Actual: null 
Stack Trace: Class.wbsendit.CMBatchCampaignStatsTest.test_LinkedCampaigns_doRun_UpdateOn: line 93, column 1
CMBatchCampaignTesttest_addMissingMemberStatusesSystem.AssertException: Assertion Failed: Expected: 3, Actual: 1 
Stack Trace: Class.wbsendit.CMBatchCampaignTest.test_addMissingMemberStatuses: line 212, column 1
DisconnectControllerTesttest_Savewbsendit.fflib_SecurityUtils.CrudException: You do not have permission to update Campaign. See: http://support.beaufort12.com/customer/en/portal/articles/2819881 
Stack Trace: Class.wbsendit.fflib_SecurityUtils.checkObjectIsUpdateable: line 413, column 1 Class.wbsendit.fflib_SecurityUtils: line 272, column 1 Class.wbsendit.DisconnectController.disconnect: line 26, column 1 Class.wbsendit.DisconnectControllerTest.test_Save: line 32, column 1
LinkCampaignControllerTesttest_autoCreateSalesforceCampaignswbsendit.fflib_SecurityUtils.CrudException: You do not have permission to insert Campaign. See: http://support.beaufort12.com/customer/en/portal/articles/2819881 
Stack Trace: Class.wbsendit.fflib_SecurityUtils.checkObjectIsInsertable: line 388, column 1 Class.wbsendit.fflib_SecurityUtils: line 137, column 1 Class.wbsendit.LinkCampaignController.autoCreateSalesforceCampaigns: line 191, column 1 Class.wbsendit.LinkCampaignControllerTest.test_autoCreateSalesforceCampaigns: line 78, column 1
LinkCampaignControllerTesttest_SaveSystem.AssertException: Assertion Failed: Same value: null 
Stack Trace: Class.wbsendit.LinkCampaignControllerTest.test_Save: line 38, column 1
ReportToListBatchTesttest_doReportToBatchSystem.LimitException: reports:Too many query rows: 50001 
Stack Trace: External entry point Class.wbsendit.ReportToListBatch.getNumberOfRows: line 469, column 1 Class.wbsendit.ReportToListBatch.doStart: line 142, column 1 Class.wbsendit.ReportToListBatch.start: line 48, column 1

User-added image
I need to create a test for it can anyone help provide the coding for the test please? (possibly with directions on how to get the process done)?


trigger  NumberOfContacts on Contact (after insert) {
set<id> setid = new set<id>();

list<account> listaccount = new list<account>();
for(contact con : trigger.new){

setid.add(con.accountid);
}

For(account acc : [select id,name,Number_of_Contacts__c, (select id from contacts)from account where id=:setid]) {
Account ac1 = new account();

ac1.id=acc.id;

ac1.Number_of_Contacts__c= acc.contacts.size();

listaccount.add(ac1);
}

update listaccount;



}
I have created an apex trigger in sandbox to add the field "Number of Contacts" in to the account in sandbox worked perfectly fine, however when deployed to production the field is empty.
THE CODE USED

trigger  NumberOfContacts on Contact (after insert) {
set<id> setid = new set<id>();

list<account> listaccount = new list<account>();
for(contact con : trigger.new){

setid.add(con.accountid);
}

For(account acc : [select id,name,Number_of_Contacts__c, (select id from contacts)from account where id=:setid]) {
Account ac1 = new account();

ac1.id=acc.id;

ac1.Number_of_Contacts__c= acc.contacts.size();

listaccount.add(ac1);
}

The ITEST CODE

@istest
02public class testnumberofcontacts {
03    @istest static void checknumbers(){
04        test.starttest();
05        account testaccount = new account(name = 'Test account');
06        insert testaccount;
07        contact testcontact = new contact(lastname = 'Samplename', accountid = testaccount.Id);
08        insert testcontact;
09        test.stopTest();
10        list<account> queriedaccount = [select name, number_of_contacts__C from account where id =: testaccount.Id];
11        decimal resultcount;
12        for(account a: queriedaccount){
13            resultcount = a.Number_of_contacts__c;
14        }
15        system.assertEquals(1, resultcount);
16    }
17 
18}

THE 7! FAILURES

CMBatchCampaignStatsTesttest_LinkedCampaignsSystem.AssertException: Assertion Failed: Expected: 25, Actual: null 
Stack Trace: Class.wbsendit.CMBatchCampaignStatsTest.test_LinkedCampaigns: line 58, column 1
CMBatchCampaignStatsTesttest_LinkedCampaigns_doRun_UpdateOnSystem.AssertException: Assertion Failed: Expected: 25, Actual: null 
Stack Trace: Class.wbsendit.CMBatchCampaignStatsTest.test_LinkedCampaigns_doRun_UpdateOn: line 93, column 1
CMBatchCampaignTesttest_addMissingMemberStatusesSystem.AssertException: Assertion Failed: Expected: 3, Actual: 1 
Stack Trace: Class.wbsendit.CMBatchCampaignTest.test_addMissingMemberStatuses: line 212, column 1
DisconnectControllerTesttest_Savewbsendit.fflib_SecurityUtils.CrudException: You do not have permission to update Campaign. See: http://support.beaufort12.com/customer/en/portal/articles/2819881 
Stack Trace: Class.wbsendit.fflib_SecurityUtils.checkObjectIsUpdateable: line 413, column 1 Class.wbsendit.fflib_SecurityUtils: line 272, column 1 Class.wbsendit.DisconnectController.disconnect: line 26, column 1 Class.wbsendit.DisconnectControllerTest.test_Save: line 32, column 1
LinkCampaignControllerTesttest_autoCreateSalesforceCampaignswbsendit.fflib_SecurityUtils.CrudException: You do not have permission to insert Campaign. See: http://support.beaufort12.com/customer/en/portal/articles/2819881 
Stack Trace: Class.wbsendit.fflib_SecurityUtils.checkObjectIsInsertable: line 388, column 1 Class.wbsendit.fflib_SecurityUtils: line 137, column 1 Class.wbsendit.LinkCampaignController.autoCreateSalesforceCampaigns: line 191, column 1 Class.wbsendit.LinkCampaignControllerTest.test_autoCreateSalesforceCampaigns: line 78, column 1
LinkCampaignControllerTesttest_SaveSystem.AssertException: Assertion Failed: Same value: null 
Stack Trace: Class.wbsendit.LinkCampaignControllerTest.test_Save: line 38, column 1
ReportToListBatchTesttest_doReportToBatchSystem.LimitException: reports:Too many query rows: 50001 
Stack Trace: External entry point Class.wbsendit.ReportToListBatch.getNumberOfRows: line 469, column 1 Class.wbsendit.ReportToListBatch.doStart: line 142, column 1 Class.wbsendit.ReportToListBatch.start: line 48, column 1

User-added image
I need to create a test for it can anyone help provide the coding for the test please? (possibly with directions on how to get the process done)?


trigger  NumberOfContacts on Contact (after insert) {
set<id> setid = new set<id>();

list<account> listaccount = new list<account>();
for(contact con : trigger.new){

setid.add(con.accountid);
}

For(account acc : [select id,name,Number_of_Contacts__c, (select id from contacts)from account where id=:setid]) {
Account ac1 = new account();

ac1.id=acc.id;

ac1.Number_of_Contacts__c= acc.contacts.size();

listaccount.add(ac1);
}

update listaccount;



}
I have created an apex trigger in sandbox to add the field "Number of Contacts" in to the account in sandbox worked perfectly fine, however when deployed to production the field is empty.