• Jeremiah Cochran
  • NEWBIE
  • 70 Points
  • Member since 2016

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 4
    Questions
  • 6
    Replies
Hi everyone, I have been working on the OrderTest apex test class and have been getting good coverage so far on much of my code. However, one area I seem to be stuck on is writing the test class for the OrderUpdate_UnitTest in relation to the AnnouncementsQueueable class, which sends off announcements to the chatter group when a message has been posted. 

As I run all tests, the OrderUpdate_UnitTest fails with the message.
System.AsyncException: Maximum stack depth has been reached.​

Class.AnnouncementQueueable.PostAnnouncements: line 30, column 1
Class.AnnouncementQueueable.execute: line 14, column 1​

My code for the OrderUpdate is below followed by AnnouncementsQueueable 
static testmethod void OrderUpdate_UnitTest (){
        test.startTest();
        Order rec = [select id, Status from Order limit 1];
        Product2 prod = [SELECT Family,Id,Name,Quantity_Ordered__c,Quantity_Remaining__c FROM Product2 limit 1];
        system.debug('kkk '+prod.Quantity_Ordered__c);
        rec.status = constants.ACTIVATED_ORDER_STATUS;
        Update rec;
        Product2 updatedprod = [SELECT Family,Id,Name,Quantity_Ordered__c,Quantity_Remaining__c FROM Product2 limit 1];
        
        system.debug('kkk '+updatedprod.Quantity_Ordered__c);
        TestDataFactory.VerifyQuantityOrdered(prod,updatedprod,constants.DEFAULT_ROWS);
         test.stopTest();
    }
 
/**
 * @name AnnouncementQueueable
 * @description This class posts Chatter Announcements
**/
public class AnnouncementQueueable implements system.Queueable{

     public List<ConnectApi.AnnouncementInput> toPost;
    
    public AnnouncementQueueable(List<ConnectApi.AnnouncementInput> toPost){
        this.toPost = toPost;
    }

    public void execute(QueueableContext context){
          PostAnnouncements(toPost);
     }


    /**
     * @name postAnnouncements
     * @description This method is provided for you to facilitate the Super Badge
    **/
     public static void PostAnnouncements(List<ConnectApi.AnnouncementInput> announcements){
        while ( announcements.size() > 0 ){
            if ( Limits.getDMLStatements() < Limits.getLimitDMLStatements() && !test.isRunningTest()){ 
                ConnectApi.AnnouncementInput a = announcements.remove(0);
                ConnectApi.Announcements.postAnnouncement('Internal', a);
            } else {
                AnnouncementQueueable announcementQueuable = new AnnouncementQueueable(announcements);
//        		announcementQueuable.toPost = announcements;
                System.enqueueJob(announcementQueuable);
                break;
            }
        }
        if ( announcements.size() > 0 && !test.isRunningTest() ){
            AnnouncementQueueable q = new AnnouncementQueueable(announcements);
//            q.toPost = announcements;
			System.enqueueJob(q);
            //ToDo: Enqueue the above instance of announcementQueueable
            
        }
    }
}

 
Hi, I'm getting some errors later in this super badge, which is causing my component to not work properly, I believe this is related to poor code and I need some help cleaning it up. Here is what I have so far.

BoatSearch.cmp
<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes" access="global" >
    <aura:handler name="formsubmit"
                  event="c:formsubmit"
                  action="{!c.onFormSubmit}"
                  phase="capture"/>
    
    <lightning:card title="Find a Boat" class="slds-m-top_10px" >
     <c:BoatSearchForm />
</lightning:card>    
<lightning:card title="Matching Boats" >
     <c:BoatSearchResults aura:id="BSRcmp"/>
</lightning:card>
</aura:component>
BoatSearchController.js
({
    onFormSubmit : function(component, event, helper){
        console.log("event received by BoatSearchController.js");
        var formData = event.getParam("formData");
        var boatTypeId = formData.boatTypeId;
        var BSRcmp = component.find("BSRcmp");
        var auraMethodResult = BSRcmp.search(boatTypeId);
        console.log("auraMethodResult: " + auraMethodResult);
    }

})
BoatTypeController.apex
public class BoatTypeController {
@AuraEnabled
    public static List<String> getpickval() {
        List<String> options = new List<String>();

        Schema.DescribeFieldResult fieldResult = BoatType__c.Name.getDescribe();

        List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues();

        for (Schema.PicklistEntry f: ple) {
            options.add(f.getLabel());
        }       
        return options;
    }
}









 
I have built the reports and dashboards as outlined in the requirements, but I'm getting the following error "Challenge Not yet complete... here's what's wrong: Couldn't find a component with the title 'My Top Accounts'."  
User-added image

However, I have the component on the dashboard as you can see below.
User-added image
What am I missing?
I'm trying to generate random geolocation codes and assign them to a record when it is created, These records are simply dummy data to use for testing purposes but for my test to work properly I need to set random geolocation codes. Here is what I have so far, but I can't get the geocode to generate:
 
List<Location__c> locat = new List<Location__c>();
for (Integer a = 0; a <5; a++) {
  locat.add(new Location__c(Location_Name__c = 'Location ' + a ));
   
	locat.GeoCode__Latitude__s = getRandomInteger();
    locat.GeoCode__Longitude__s = getRandomLong();
}

insert locat;

 
Hi, I'm new to writing triggers and need some assistance with the following code, I have it work for the most part, what is giving me trouble is trying to figure out how to prevent it from creating multiple child cases for the same parent case. For example, if the parent case that fires the trigger has 2 secret keywords, then 2 child cases are created when I only want 1. Thanks in advance.

Here is the trigger code:

trigger CheckSecretInformation on Case (after insert, before update) 
{
    String childCaseSubject = 'Warning this case may contain secret info';

//Step 1: Create a collection containing each secret keyword
    Set<String> secretKeywords = new Set<String>();
    secretKeywords.add('Credit Card');
    secretKeywords.add('Social Security');
    secretKeywords.add('SSN');
    secretKeywords.add('Passport');
    secretKeywords.add('Body Weight');

    //Step 2: Check to see if a case contains any of the secret keywords
    List<Case> casesWithSecretInfo = new List<Case>();
    List<String> secretKeywordsFound = new List<String>();
    
    for (Case myCase : Trigger.new) 
    {
        if (myCase.Subject != childCaseSubject) 
        {
            for (String keyword : secretKeywords) 
            {
                 if (myCase.Description !=null && myCase.Description.containsIgnoreCase(keyword)) 
                {
                    casesWithSecretInfo.add(myCase);
                    secretKeywordsFound.add(keyword);
                    
                    System.debug ('Case ' +myCase.ID + ' includes secret keyword ' +keyword);
                  }
            }
        }

    }
        //Step 3: If a case contains secret keywords, create a child case
        List<Case> caseToCreate = new List<Case>();
        for (Case caseWithSecretInfo : casesWithSecretInfo) 
        {
            if (caseWithSecretInfo.Cases.Size()<1) 
             {
                       
            Case childCase = new Case();
            childCase.Subject = childCaseSubject;
            childCase.ParentId = caseWithSecretInfo.Id;
            childCase.Priority = 'High';
            childCase.IsEscalated = true;
            childCase.Description = 'At least one of the following keywords were found ' + secretKeywordsfound;
            caseToCreate.add(childCase);
             }
        }

        insert caseToCreate;
}
Hi everyone, I have been working on the OrderTest apex test class and have been getting good coverage so far on much of my code. However, one area I seem to be stuck on is writing the test class for the OrderUpdate_UnitTest in relation to the AnnouncementsQueueable class, which sends off announcements to the chatter group when a message has been posted. 

As I run all tests, the OrderUpdate_UnitTest fails with the message.
System.AsyncException: Maximum stack depth has been reached.​

Class.AnnouncementQueueable.PostAnnouncements: line 30, column 1
Class.AnnouncementQueueable.execute: line 14, column 1​

My code for the OrderUpdate is below followed by AnnouncementsQueueable 
static testmethod void OrderUpdate_UnitTest (){
        test.startTest();
        Order rec = [select id, Status from Order limit 1];
        Product2 prod = [SELECT Family,Id,Name,Quantity_Ordered__c,Quantity_Remaining__c FROM Product2 limit 1];
        system.debug('kkk '+prod.Quantity_Ordered__c);
        rec.status = constants.ACTIVATED_ORDER_STATUS;
        Update rec;
        Product2 updatedprod = [SELECT Family,Id,Name,Quantity_Ordered__c,Quantity_Remaining__c FROM Product2 limit 1];
        
        system.debug('kkk '+updatedprod.Quantity_Ordered__c);
        TestDataFactory.VerifyQuantityOrdered(prod,updatedprod,constants.DEFAULT_ROWS);
         test.stopTest();
    }
 
/**
 * @name AnnouncementQueueable
 * @description This class posts Chatter Announcements
**/
public class AnnouncementQueueable implements system.Queueable{

     public List<ConnectApi.AnnouncementInput> toPost;
    
    public AnnouncementQueueable(List<ConnectApi.AnnouncementInput> toPost){
        this.toPost = toPost;
    }

    public void execute(QueueableContext context){
          PostAnnouncements(toPost);
     }


    /**
     * @name postAnnouncements
     * @description This method is provided for you to facilitate the Super Badge
    **/
     public static void PostAnnouncements(List<ConnectApi.AnnouncementInput> announcements){
        while ( announcements.size() > 0 ){
            if ( Limits.getDMLStatements() < Limits.getLimitDMLStatements() && !test.isRunningTest()){ 
                ConnectApi.AnnouncementInput a = announcements.remove(0);
                ConnectApi.Announcements.postAnnouncement('Internal', a);
            } else {
                AnnouncementQueueable announcementQueuable = new AnnouncementQueueable(announcements);
//        		announcementQueuable.toPost = announcements;
                System.enqueueJob(announcementQueuable);
                break;
            }
        }
        if ( announcements.size() > 0 && !test.isRunningTest() ){
            AnnouncementQueueable q = new AnnouncementQueueable(announcements);
//            q.toPost = announcements;
			System.enqueueJob(q);
            //ToDo: Enqueue the above instance of announcementQueueable
            
        }
    }
}

 
I am getting the error:

Ensure that you modify the constructCollaborationGroup method so that it has the correct return type and is not an instance method

Here is that method:
public CollaborationGroup ConstructCollaborationGroup(){
        //ToDo: Ensure this method returns a single Chatter CollaborationGroup
        //    whose Name starts with 'TEST' followed by the INVENTORY_ANNOUNCEMENTS constant
        //    and configured so anyone can join, see and post updates.
        //    
        CollaborationGroup ChatterGroup = new CollaborationGroup(
              Name = 'TEST'+Constants.INVENTORY_ANNOUNCEMENTS,  
              CollaborationType = 'Public',
              CanHaveGuests = true,
              IsArchived = false,
              IsAutoArchiveDisabled = true
        );
        insert ChatterGroup;
        return ChatterGroup;
        
    }
Any ideas on what is wrong. If I run
public void SetupTestData(Integer cnt){
        //ToDo: Ensure this method calls each of the construct methods
        //  and inserts the results for use as test data.
        //  
        CollaborationGroup g = this.ConstructCollaborationGroup();
        List<Account> accounts = this.ConstructAccounts(10);
        List<Contact> contacts = this.ConstructContacts(10,accounts);
        List<Product2> products = this.ConstructProducts(10);
        List<PricebookEntry> pes = this.ConstructPricebookEntries(products);
        List<Order>orders = this.ConstructOrders(10,accounts);
        List<OrderItem> ois = this.ConstructOrderItems(10,pes,orders);
            
    }
All works as expected. I am not sure what I am missing in the ConstructCollaborationGroup method. It is returing a CollaborationGroup and is not static.

Thanks!
I have built the reports and dashboards as outlined in the requirements, but I'm getting the following error "Challenge Not yet complete... here's what's wrong: Couldn't find a component with the title 'My Top Accounts'."  
User-added image

However, I have the component on the dashboard as you can see below.
User-added image
What am I missing?
Hi, I'm new to writing triggers and need some assistance with the following code, I have it work for the most part, what is giving me trouble is trying to figure out how to prevent it from creating multiple child cases for the same parent case. For example, if the parent case that fires the trigger has 2 secret keywords, then 2 child cases are created when I only want 1. Thanks in advance.

Here is the trigger code:

trigger CheckSecretInformation on Case (after insert, before update) 
{
    String childCaseSubject = 'Warning this case may contain secret info';

//Step 1: Create a collection containing each secret keyword
    Set<String> secretKeywords = new Set<String>();
    secretKeywords.add('Credit Card');
    secretKeywords.add('Social Security');
    secretKeywords.add('SSN');
    secretKeywords.add('Passport');
    secretKeywords.add('Body Weight');

    //Step 2: Check to see if a case contains any of the secret keywords
    List<Case> casesWithSecretInfo = new List<Case>();
    List<String> secretKeywordsFound = new List<String>();
    
    for (Case myCase : Trigger.new) 
    {
        if (myCase.Subject != childCaseSubject) 
        {
            for (String keyword : secretKeywords) 
            {
                 if (myCase.Description !=null && myCase.Description.containsIgnoreCase(keyword)) 
                {
                    casesWithSecretInfo.add(myCase);
                    secretKeywordsFound.add(keyword);
                    
                    System.debug ('Case ' +myCase.ID + ' includes secret keyword ' +keyword);
                  }
            }
        }

    }
        //Step 3: If a case contains secret keywords, create a child case
        List<Case> caseToCreate = new List<Case>();
        for (Case caseWithSecretInfo : casesWithSecretInfo) 
        {
            if (caseWithSecretInfo.Cases.Size()<1) 
             {
                       
            Case childCase = new Case();
            childCase.Subject = childCaseSubject;
            childCase.ParentId = caseWithSecretInfo.Id;
            childCase.Priority = 'High';
            childCase.IsEscalated = true;
            childCase.Description = 'At least one of the following keywords were found ' + secretKeywordsfound;
            caseToCreate.add(childCase);
             }
        }

        insert caseToCreate;
}