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
Alex StalteriAlex Stalteri 

Received Error when Validating Apex Class before Deployment

Hi All,

I'm a new admin and do not have any developer experience, so any help would be greatly appreciated!

I've added new tasks to an existing apex class button and it works perfectly in my sandbox instance but when I validate the change in production before deployment I received the following error code:

System.AssertException: Assertion Failed 
Stack Trace: Class.TestCreateOnboardingTasks.verifyTasksCreated: line 51, column 1

This is line 45-59 in my apex class:

Task t = new Task();
        t.WhatId = accountID;
        t.WhoId = champion.Id;
        t.Subject = 'Onboarding: Day 7';
        t.ActivityDate = a.Subscription_Start_Date__c.addDays(7);
        t.OwnerId = a.OwnerId;
        insert t;
        
        t = new Task();
        t.WhatId = accountID;
        t.WhoId = champion.Id;
        t.Subject = 'Onboarding: Day 15';
        t.ActivityDate = a.Subscription_Start_Date__c.addDays(15);
        t.OwnerId = a.OwnerId;
        insert t;

Any ideas on what to do for it to pass the validation test?
Shawn Reichner 29Shawn Reichner 29
I think we will ned to see the remainder of the class in order to fully help. 
Alex StalteriAlex Stalteri
   Task t = new Task();
        t.WhatId = accountID;
        t.WhoId = champion.Id;
        t.Subject = 'Onboarding: Day 7';
        t.ActivityDate = a.Subscription_Start_Date__c.addDays(7);
        t.OwnerId = a.OwnerId;
        insert t;
        
        t = new Task();
        t.WhatId = accountID;
        t.WhoId = champion.Id;
        t.Subject = 'Onboarding: Day 15';
        t.ActivityDate = a.Subscription_Start_Date__c.addDays(15);
        t.OwnerId = a.OwnerId;
        insert t;
        
        t = new Task();
        t.WhatId = accountID;
        t.WhoId = champion.Id;
        t.Subject = 'Onboarding: Day 30';
        t.ActivityDate = a.Subscription_Start_Date__c.addDays(30);
        t.OwnerId = a.OwnerId;
        insert t;
        
        t = new Task();
        t.WhatId = accountID;
        t.WhoId = champion.Id;
        t.Subject = 'Onboarding: Day 45';
        t.ActivityDate = a.Subscription_Start_Date__c.addDays(45);
        t.OwnerId = a.OwnerId;
        insert t;
        
        t = new Task();
        t.WhatId = accountID;
        t.WhoId = champion.Id;
        t.Subject = 'Onboarding: Day 60';
        t.ActivityDate = a.Subscription_Start_Date__c.addDays(60);
        t.OwnerId = a.OwnerId;
        insert t;
        
        t = new Task();
        t.WhatId = accountID;
        t.WhoId = champion.Id;
        t.Subject = 'Onboarding: Day 90';
        t.ActivityDate = a.Subscription_Start_Date__c.addDays(90);
        t.OwnerId = a.OwnerId;
        insert t;
        
        t = new Task();
        t.WhatId = accountID;
        t.WhoId = champion.Id;
        t.Subject = '6 Month Check-in';
        t.ActivityDate = a.Subscription_Start_Date__c.addMonths(6);
        t.OwnerId = a.OwnerId;
        t.Description = 'Feedback Request';
        insert t;
        
        t = new Task();
        t.WhatId = accountID;
        t.WhoId = champion.Id;
        t.Subject = 'Start Renewal Process';
        t.ActivityDate = a.Subscription_Start_Date__c.addMonths(10);
        t.OwnerId = a.OwnerId;
        insert t;
        
        t = new Task();
        t.WhatId = accountID;
        t.WhoId = champion.Id;
        t.Subject = 'Call - Kickoff Call';
        t.ActivityDate = a.Subscription_Start_Date__c.addDays(2);
        t.OwnerId = a.OwnerId;
        t.Description = 'Onboarding Deck:\n\nCall notes from Sales Cycle:\n\nIntroductions\nAttendees:\n\nOnboarding Plan\nOverarching Goal:\nTeam Strategy (who will be involved):\n\nCustomizable Sections\nSSO(Professional +):\nSalesforce(Professional +):\nExport Template:\nTeam Training:\n\nPhase 1\nWhere is your content now?:\nLibrary Planning Document Next Steps: \nDo we need to set permissions?:\n\nTheir Questions\n\nAction Items';
        insert t;
        
        t = new Task();
        t.WhatId = accountID;
        t.WhoId = champion.Id;
        t.Subject = 'Onboarding: Day 120';
        t.ActivityDate = a.Subscription_Start_Date__c.addDays(120);
        t.OwnerId = a.OwnerId;
        t.Description = 'Review Request(L1)';
        insert t;
        
        t = new Task();
        t.WhatId = accountID;
        t.WhoId = champion.Id;
        t.Subject = 'Confirm Renewal Notification Sent';
        t.ActivityDate = a.Subscription_Start_Date__c.addDays(365);
        t.OwnerId = a.OwnerId;
        t.Description = 'Confirm Billing Address in Fusebill matches Salesforce\nConfirm Billing Contact\nConfirm Notification Sent\nConfirm ARR\nConfirm Renewal Date';
        insert t;
        
        return 'Onboarding Tasks created successfully!';
        
    }
}
Amol ChAmol Ch
Hi Alex,

You need to check the all developed processes related to test class in sandbox and production both, there should be difference in process that restrict to run the test class in production,.

Now Investigate what is different Process in production compare to sandbox that cause test class which fails to run.

Example: If you are inserting data in test class, so you unable to insert data in due to valditiaon executed to true, loookup filter or workflow etc.  Because that process are available in production and not available in sandbox. In this case test class will fails in production.

let me know if it helps for you.