Important Update: thank you all for the advice. It turns out I did in fact have some differences between the sandbox and the active org that were causing the failure. Your advice has been written down in ink for the future. Blessings on all of you.
I used the Developer Console to make 2 classes. 1 simple class that queries some simple task info. 1 test class to test the class. When I run the test class in the sandbox developer console, they pass. Not only do they pass, but i output the values of the test immediately before and after the assertion that tests those values. Perfect. Exactly what I expected. Exactly. Yet when I migrate the class over from the sandbox to the active org, salesforce tries to validate the two classes and when it runs my exact test cases, the value is supposedly null. Test fails. No update for the org. What gives?
Edit1: Sorry I made this post without having the code posted as well. I’m at home and don’t have access to the code. But I will edit this post again first thing when I get to work in the morning.
Edit2: here is the code as promised. Class Code: public with sharing class TaskRelatedListController { @AuraEnabled(cacheable=true) public static List<Task> getTasks() { return [SELECT Id, Subject, Status, ActivityDate FROM Task LIMIT 10]; }} Test Class Code: @isTestpublic class TaskRelatedListControllerTest { @isTest static void testGetTasks() { // Create test data List<Task> testTasks = new List<Task>(); for (Integer i = 0; i < 10; i ) { testTasks.add(new Task( Subject='Test Task ' i, Status='Not Started', ActivityDate=System.today().addDays(i) )); } insert testTasks; // Call the controller method to get tasks List<Task> fetchedTasks = TaskRelatedListController.getTasks(); // Assertions System.assertEquals(10, fetchedTasks.size(), 'Number of fetched tasks should match test data'); for (Integer i = 0; i < 10; i ) { System.assertEquals('Test Task ' i, fetchedTasks[i].Subject, 'Subject should match'); System.assertEquals('Not Started', fetchedTasks[i].Status, 'Status should match'); System.assertEquals(System.today().addDays(i), fetchedTasks[i].ActivityDate, 'ActivityDate should match'); } }}
Subreddit
Post Details
- Posted
- 1 year ago
- Reddit URL
- View post on reddit.com
- External URL
- reddit.com/r/salesforce/...