Coming soon - Get a detailed view of why an account is flagged as spam!
view details
5
New to Apex. Salesforce wont validate my changes.
Post Flair (click to view more posts with a particular flair)
Post Body

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');        }    }}

Author
Account Strength
100%
Account Age
5 years
Verified Email
Yes
Verified Flair
No
Total Karma
24,521
Link Karma
3,578
Comment Karma
20,430
Profile updated: 1 week ago
Posts updated: 1 year ago

Subreddit

Post Details

We try to extract some basic information from the post title. This is not always successful or accurate, please use your best judgement and compare these values to the post title and body for confirmation.
Posted
1 year ago