• Darrell Waddell 223
  • NEWBIE
  • 0 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 4
    Questions
  • 2
    Replies
Class: pc_tst_systemStatusHistoryViewMethod: createView_SingleEnvironmentMultipleHistories_OneInTimeFrameRecentError message: 
System.AssertException: Assertion Failed: Expected: 1, Actual: 2

Stack trace: Class.pc_tst_systemStatusHistoryView.createView_SingleEnvironmentMultipleHistories_OneInTimeFrameRecent: line 121, column 1

 
@isTest
private class pc_tst_systemStatusHistoryView {
    @isTest
    static void createView_SingleEnvironmentSingleHistory_AfterTimeFrame() {
        // Arrange
        User user = pc_tst_generateData.generateCommunityUser();
        Environment__c env = setupData(user);
        pc_systemStatusHistoryView view;

        // Act
        system.runAs(user) {
            Test.startTest();
            view = new pc_systemStatusHistoryView();
            Test.stopTest();
        }

        // Assert
        system.assertEquals(1, view.assetsByProductType.size());

        pc_systemStatusAssets assets = view.assetsByProductType.get(env.Product_Type__c);
        system.assertEquals(1, assets.environments.size());
        system.assertEquals(1, assets.historiesByEnvironment.size());
    }

    @isTest
    static void createView_SingleEnvironmentSingleHistory_JustInTimeFrame() {
        // Arrange
        User user = pc_tst_generateData.generateCommunityUser();
        Environment__c env = setupData(user);
        updateLatestHistory(env, Datetime.newInstanceGMT(Datetime.now().addDays(-1).dateGMT(),
            Time.newInstance(23, 59, 59, 999)), (Datetime)null);
        pc_systemStatusHistoryView view;

        // Act
        system.runAs(user) {
            Test.startTest();
            view = new pc_systemStatusHistoryView();
            Test.stopTest();
        }

        // Assert
        system.assertEquals(1, view.assetsByProductType.size());

        pc_systemStatusAssets assets = view.assetsByProductType.get(env.Product_Type__c);
        system.assertEquals(1, assets.environments.size());
        system.assertEquals(1, assets.historiesByEnvironment.size());
        system.assertEquals(1, assets.historiesByEnvironment.get(env.Id).histories.size());
    }

    @isTest
    static void createView_SingleEnvironmentSingleHistory_BeforeTimeFrame() {
        // Arrange
        User user = pc_tst_generateData.generateCommunityUser();
        Environment__c env = setupData(user);
        updateLatestHistory(env, Datetime.now().addDays(-40), (Datetime)null);
        pc_systemStatusHistoryView view;

        // Act
        system.runAs(user) {
            Test.startTest();
            view = new pc_systemStatusHistoryView();
            Test.stopTest();
        }

        // Assert
        system.assertEquals(1, view.assetsByProductType.size());

        pc_systemStatusAssets assets = view.assetsByProductType.get(env.Product_Type__c);
        system.assertEquals(1, assets.environments.size());
        system.assertEquals(1, assets.historiesByEnvironment.size());
        system.assertEquals(1, assets.historiesByEnvironment.get(env.Id).histories.size());
    }

    @isTest(isParallel=false)
    static void createView_SingleEnvironmentMultipleHistories_InTimeFrame() {
        // Arrange
        User user = pc_tst_generateData.generateCommunityUser();
        Environment__c env = setupData(user);
        updateLatestHistory(env, Datetime.now().addDays(-40), Datetime.now().addDays(-15));
        addHistory(env, Datetime.now().addDays(-15), (Datetime)null);
        pc_systemStatusHistoryView view;

        // Act
        system.runAs(user) {
            Test.startTest();
            view = new pc_systemStatusHistoryView();
            Test.stopTest();
        }

        // Assert
        system.assertEquals(1, view.assetsByProductType.size());

        pc_systemStatusAssets assets = view.assetsByProductType.get(env.Product_Type__c);
        system.assertEquals(1, assets.environments.size());
        system.assertEquals(1, assets.historiesByEnvironment.size());
        system.assertEquals(2, assets.historiesByEnvironment.get(env.Id).histories.size());
    }

    @isTest
    static void createView_SingleEnvironmentMultipleHistories_OneInTimeFrameRecent() {
        // Arrange
        User user = pc_tst_generateData.generateCommunityUser();
        Environment__c env = setupData(user);
        updateLatestHistory(env, Datetime.now().addDays(-1), Datetime.now().addHours(-1));
        addHistory(env, Datetime.now().addHours(-1), (Datetime)null);
        pc_systemStatusHistoryView view;

        // Act
        system.runAs(user) {
            Test.startTest();
            view = new pc_systemStatusHistoryView();
            Test.stopTest();
        }

        // Assert
        system.assertEquals(1, view.assetsByProductType.size());

        pc_systemStatusAssets assets = view.assetsByProductType.get(env.Product_Type__c);
        system.assertEquals(1, assets.environments.size());
        system.assertEquals(1, assets.historiesByEnvironment.size());
        system.assertEquals(1, assets.historiesByEnvironment.get(env.Id).histories.size());
    }

    @isTest
    static void createView_SingleEnvironmentMultipleHistories_OneInTimeFrameOld() {
        // Arrange
        User user = pc_tst_generateData.generateCommunityUser();
        Environment__c env = setupData(user);
        updateLatestHistory(env, Datetime.now().addDays(-42), Datetime.now().addDays(-40));
        addHistory(env, Datetime.now().addDays(-40), (Datetime)null);
        pc_systemStatusHistoryView view;

        // Act
        system.runAs(user) {
            Test.startTest();
            view = new pc_systemStatusHistoryView();
            Test.stopTest();
        }

        // Assert
        system.assertEquals(1, view.assetsByProductType.size());

        pc_systemStatusAssets assets = view.assetsByProductType.get(env.Product_Type__c);
        system.assertEquals(1, assets.environments.size());
        system.assertEquals(1, assets.historiesByEnvironment.size());
        system.assertEquals(1, assets.historiesByEnvironment.get(env.Id).histories.size());
    }

    @isTest
    static void createView_MultipleEnvironmentsSingleHistories_InTimeFrame() {
        // Arrange
        User user = pc_tst_generateData.generateCommunityUser();
        Environment__c env1 = setupData(user, 'TAM');
        updateLatestHistory(env1, Datetime.now().addDays(-7), (Datetime)null);
        Environment__c env2 = setupData(user, 'Epic');
        updateLatestHistory(env2, Datetime.now().addDays(-7), (Datetime)null);
        pc_systemStatusHistoryView view;

        system.runAs(user) {
            // Act
            Test.startTest();
            view = new pc_systemStatusHistoryView();
            Test.stopTest();
        }

        // Assert
        system.assertEquals(2, view.assetsByProductType.size());

        pc_systemStatusAssets assets1 = view.assetsByProductType.get(env1.Product_Type__c);
        system.assertEquals(1, assets1.environments.size());
        system.assertEquals(1, assets1.historiesByEnvironment.size());
        system.assertEquals(1, assets1.historiesByEnvironment.get(env1.Id).histories.size());

        pc_systemStatusAssets assets2 = view.assetsByProductType.get(env2.Product_Type__c);
        system.assertEquals(1, assets2.environments.size());
        system.assertEquals(1, assets2.historiesByEnvironment.size());
        system.assertEquals(1, assets2.historiesByEnvironment.get(env2.Id).histories.size());
    }

    @isTest
    static void getAllHistories_SingleEnvironmentSingleHistory_AfterTimeFrame() {
        // Arrange
        User user = pc_tst_generateData.generateCommunityUser();
        Environment__c env = setupData(user);
        List<System_Status_History__c> histories;

        system.runAs(user) {
            pc_systemStatusHistoryView view = new pc_systemStatusHistoryView();

            // Act
            Test.startTest();
            histories = view.getAllHistories();
            Test.stopTest();
        }

        // Assert
        system.assertEquals(0, histories.size());
    }

    @isTest
    static void getAllHistories_SingleEnvironmentSingleHistory_BeforeTimeFrame() {
        // Arrange
        User user = pc_tst_generateData.generateCommunityUser();
        Environment__c env = setupData(user);
        updateLatestHistory(env, Datetime.now().addDays(-40), (Datetime)null);
        List<System_Status_History__c> histories;

        system.runAs(user) {
            pc_systemStatusHistoryView view = new pc_systemStatusHistoryView();

            // Act
            Test.startTest();
            histories = view.getAllHistories();
            Test.stopTest();
        }

        // Assert
        system.assertEquals(1, histories.size());
    }

    @isTest
    static void getAllHistories_SingleEnvironmentMultipleHistories_InTimeFrame() {
        // Arrange
        User user = pc_tst_generateData.generateCommunityUser();
        Environment__c env = setupData(user);
        updateLatestHistory(env, Datetime.now().addDays(-40), Datetime.now().addDays(-15));
        addHistory(env, Datetime.now().addDays(-15), (Datetime)null);
        List<System_Status_History__c> histories;

        system.runAs(user) {
            pc_systemStatusHistoryView view = new pc_systemStatusHistoryView();

            // Act
            Test.startTest();
            histories = view.getAllHistories();
            Test.stopTest();
        }

        // Assert
        system.assertEquals(2, histories.size());
    }

    @isTest 
    static void getCurrentSubsetId() {
        // Arrange
        User user = pc_tst_generateData.generateCommunityUser();
        Environment__c env = setupData(user);
        Integer subsetId;
        
        system.runAs(user) {
            pc_systemStatusHistoryView view = new pc_systemStatusHistoryView();
            
            // Act
            Test.startTest();
            view.nextSubset();
            view.nextSubset();
            subsetId = view.getCurrentSubsetId();
            Test.stopTest();
        }
        
        // Assert
        system.assertEquals(2, subsetId);
    }
    
    @isTest
    static void getDatesInCurrentSubset() {
        // Arrange
        User user = pc_tst_generateData.generateCommunityUser();
        Environment__c env = setupData(user);
        List<Date> dates;

        system.runAs(user) {
            pc_systemStatusHistoryView view = new pc_systemStatusHistoryView();

            // Act
            Test.startTest();
            dates = view.getDatesInCurrentSubset();
            Test.stopTest();
        }

        // Assert
        system.assertEquals(5, dates.size());
    }

    @isTest
    static void nextSubset() {
        // Arrange
        User user = pc_tst_generateData.generateCommunityUser();
        Environment__c env = setupData(user);
        Integer subsetId;
            
        system.runAs(user) {
            pc_systemStatusHistoryView view = new pc_systemStatusHistoryView();

            // Act
            Test.startTest();
            view.nextSubset();
            subsetId = view.getCurrentSubsetId();
            Test.stopTest();
        }

        // Assert
        system.assertEquals(1, subsetId);
    }
    
    @isTest
    static void nextSubset_Clamped() {
        // Arrange
        User user = pc_tst_generateData.generateCommunityUser();
        Environment__c env = setupData(user);
        Integer subsetId;

        system.runAs(user) {
            pc_systemStatusHistoryView view = new pc_systemStatusHistoryView();

            // Act
            Test.startTest();
            view.nextSubset();
            view.nextSubset();
            view.nextSubset();
            view.nextSubset();
            view.nextSubset();
            view.nextSubset();
            subsetId = view.getCurrentSubsetId();
            Test.stopTest();
        }

        // Assert
        system.assertEquals(5, subsetId);
    }
    
    @isTest
    static void prevSubset() {
        // Arrange
        User user = pc_tst_generateData.generateCommunityUser();
        Environment__c env = setupData(user);
        Integer subsetId;

        system.runAs(user) {
            pc_systemStatusHistoryView view = new pc_systemStatusHistoryView();

            // Act
            Test.startTest();
            view.nextSubset();
            view.prevSubset();
            subsetId = view.getCurrentSubsetId();
            Test.stopTest();
        }

        // Assert
        system.assertEquals(0, subsetId);
    }
    
    @isTest
    static void prevSubset_Clamped() {
        // Arrange
        User user = pc_tst_generateData.generateCommunityUser();
        Environment__c env = setupData(user);
        Integer subsetId;

        system.runAs(user) {
            pc_systemStatusHistoryView view = new pc_systemStatusHistoryView();

            // Act
            Test.startTest();
            view.prevSubset();
            subsetId = view.getCurrentSubsetId();
            Test.stopTest();
        }

        // Assert
        system.assertEquals(0, subsetId);
    }

    static Environment__c setupData(User user) {
        return setupData(user, 'TAM');
    }

    static Environment__c setupData(User user, String productType) {
        Id accountId = [SELECT Contact.AccountId FROM User WHERE Id =: user.Id].Contact.AccountId;

        Environment__c env = new Environment__c(
            Name = 'my awesome environment',
            Product_Type__c = productType,
            Data_Center__c = 'NAUSE1',
            Instance__c = '00',
            Status__c = 'Available',
            Status_Message__c = 'my awesome status message',
            French_Status_Message__c = 'my awesome french status message',
            Maintenance_Message__c = 'my awesome maintenance message',
            French_Maintenance_Message__c = 'my awesome french maintenance message');
        insert env;

        Product_Access__c access = new Product_Access__c(
            Name = 'my awesome access',
            Product_Group_Category__c = 'Applied TAM',
            Account__c = accountId,
            Environment__c = env.Id,
            Start_Date__c = Datetime.now().dateGMT());
        insert access;

        return env;
    }

    static void addHistory(Environment__c env, Datetime startTime, Datetime endTime) {
        env.Status_Message__c = 'my really awesome status message v. ' + Math.random();
        update env;

        updateLatestHistory(env, startTime, endTime);
    }

    static void updateLatestHistory(Environment__c env, Datetime startTime, Datetime endTime) {
        System_Status_History__c history = [
            SELECT Start_Time__c, End_Time__c, Environment__r.Id
            FROM System_Status_History__c
            WHERE Environment__r.Id =: env.Id
            AND End_Time__c = null];

        history.Start_Time__c = startTime;
        history.End_Time__c = endTime;
        update history;
    }
}




 

Getting the following error while checking Challenge 8 on the Advanced Apex Specialist Super Badge:

 

Challenge Not yet complete... here's what's wrong:
There was an unexpected error in your org which is preventing this assessment check from completing: System.NullPointerException: Attempt to de-reference a null object Close errors


I also have all this code coverage and still cannot pass the challenge

My overall code coverage

Getting this error:
Error: Compile Error: unexpected token: 'List' at line 44 column 8

public String SupportTierValue {
  get {
           
        List tmpAcct = [SELECT Id, Name, Support_Tier__c
        FROM Account
        WHERE Id IN 
        (SELECT AccountId 
        FROM user 
        WHERE username=:UserInfo.getUsername()
        )
        LIMIT 1
        ];
        if (tmpAcct.size() > 0) {
        String SupportTier = tmpAcct[0].Support_Tier__c;
        }
        else {
        String SupportTier = 'SomeDefaultValue';
        }
        
      
       
    }
    return SupportTierValue;
  }
  private set;

}

I'm having issues with adding a Menu Item to the Navigation Menu within Community Builder.

User-added image
User-added image

This is what I want: Add a menu item called "My Profile" and have it go directly to the User Profile page.
What's happening: The URL for My Profile requires one or more parameters. Please replace each parameter with the appropriate value.

Name: My Profile

Type: Community Page
Page: User Profile
URL: /profile/:recordId

Getting the following error while checking Challenge 8 on the Advanced Apex Specialist Super Badge:

 

Challenge Not yet complete... here's what's wrong:
There was an unexpected error in your org which is preventing this assessment check from completing: System.NullPointerException: Attempt to de-reference a null object Close errors


I also have all this code coverage and still cannot pass the challenge

My overall code coverage