• Poonam Agarwal 7
  • NEWBIE
  • 10 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 4
    Questions
  • 3
    Replies
Hi, I am facing error - Ensure that you implement the Queueable interface in the AnnouncementQueueable class. 

I am getting proper response....and implemented trigger, Product2Helper and AnnouncementQueable class as per the trailhead 



Follwoing is my code -
product2Trigger --->
trigger product2Trigger on Product2 (after update) {
   Product2Helper.AfterUpdate((List<Product2>)trigger.new,(List<Product2>)trigger.old);
   
}

Product2Helper Class ---->
public class Product2Helper {

    /**
     * @name COLLABORATION_GROUP
     * @description List of CollaborationGroup used in both business and test logic
    **/
    static List<CollaborationGroup> COLLABORATION_GROUP = [
        SELECT Id
        FROM CollaborationGroup
        WHERE Name = :Constants.INVENTORY_ANNOUNCEMENTS 
        OR Name = :('TEST'+Constants.INVENTORY_ANNOUNCEMENTS)
        LIMIT 1
    ];

    /**
     * @name afterUpdate
     * @description called by product2 Trigger on After Update
     * @param List<Product2> newList
     * @param List<Product2> oldList
    **/
    public static void AfterUpdate(List<Product2> prodList, List<Product2> prodOldList){
        //ToDo: Declare a List of Product2 records named needsAnnouncement

        //ToDo: Declare a Map of Strings to Inventory_Setting__mdt records

        //ToDo: Loop through a query of Inventory_Setting__mdt records and populate the Map with Name as the key

        //ToDo: Loop through the Products in newList
        // Use the corresponding Inventory Setting record to determine the correct Low Quantity Alert
        // If the Product's Quantity Remaining has been changed to less than the Low Quantity Alert
        //      add it to the needsAnnouncement list

        //ToDo: Pass records to the postAlerts method
        List<Product2> needsAnnouncement = new List<Product2>();
        Map<String,Inventory_Setting__mdt> mapInventory = new Map<String,Inventory_Setting__mdt>();
        for(Inventory_Setting__mdt inv : [select id, DeveloperName, Low_Quantity_Alert__c from Inventory_Setting__mdt]){
            mapInventory.put(inv.DeveloperName,inv);
        }
        
        for(integer i=0;i<prodList.size();i++)
        {
            if(mapInventory.get(prodList[i].Family).Low_Quantity_Alert__c > prodList[i].Quantity_Remaining__c && 
                mapInventory.get(prodList[i].Family).Low_Quantity_Alert__c <= prodOldList[i].Quantity_Remaining__c)
            {
                needsAnnouncement.add(prodList[i]);
            }
        }
        PostAlerts(needsAnnouncement);
    }

    /**
     * @name postAlerts
     * @description called by product2 Trigger on After Update
     * @param List<Product2> productList
    **/
    public static void PostAlerts(List<Product2> productList){
        List<ConnectApi.AnnouncementInput> toPost = new List<ConnectApi.AnnouncementInput>();
        for ( Product2 p : productList ){
            // ToDo: Construct a new AnnouncementInput for the Chatter Group so that it:
            // expires in a day
            // does not notify users via email.
            // and has a text body that includes the name of the product followed by the INVENTORY_LEVEL_LOW constant
            ConnectApi.MessageBodyInput msgBody = new ConnectApi.MessageBodyInput();
            ConnectApi.AnnouncementInput tempPost = new ConnectApi.AnnouncementInput();
            ConnectApi.TextSegmentInput textSegment = new ConnectApi.TextSegmentInput();
            textSegment.text = p.Name +'  '+ Constants.INVENTORY_LEVEL_LOW;
            msgBody.messageSegments = new List<ConnectApi.MessageSegmentInput>();
            msgBody.messageSegments.add(textSegment);
            
            tempPost.body = msgBody;
            tempPost.expirationDate = DateTime.Now().AddDays(1);
            tempPost.parentId = COLLABORATION_GROUP[0].id;
            tempPost.sendEmails = false;
            toPost.add(tempPost);
         }
    
        // ToDo: Create and enqueue an instance of the announcementQueuable class with the list of Products
        AnnouncementQueueable annQue = new AnnouncementQueueable(toPost);
        //annQue.toPost = toPost;
        system.enqueueJob(annQue);
    }
}

AnnouncementQueueable Class ---->
/**
 * @name AnnouncementQueueable
 * @description This class posts Chatter Announcements
**/
public class AnnouncementQueueable implements Queueable{

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

    //ToDo: Modify this class to implement the Queueable interface and call the postAnnouncements method
    public void execute(System.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 {
                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
        }
    }

}

Any help would be really appreciated.
Hi, I am facing issue with test coverage of Constants class....it shows 62%......It should automatically be covered by testing other classes except for  this line of code because it  cannot be executed in testing context--->
 else {
            if (stdPriceBook == null) 
                stdPriceBook    = [select id, name from Pricebook2 where isStandard = true limit 1];
               STANDARD_PRICEBOOK_ID = (stdPriceBook!=null)?stdPriceBook.id:'';
        }
Below is the coverage shown...it is not showing blue for other lines nor it is showing red-----Any help would be appreciated

User-added image
Hi,
I am facing issue with challenge 6 it gives error as in below screenshot

User-added image
 

I don't understand I have created the onBoatSelected controller function to run when BoatSelected application event is fired...but still I am getting this error. I have checked console log and I am getting all the boat details in my BoatDetails component. Below is my code -

BoatTile.cmp

<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes" access="global">
    <aura:attribute name="boat" type="Boat__C"/>
    <aura:attribute name="selected" type="Boolean"/>
    <aura:registerEvent name="BoatSelect" type="c:BoatSelect"/>
    <aura:registerEvent name="BoatSelected" type="c:BoatSelected"/>
    <!--<lightning:button class="tile{! v.selected ? 'selected' : 'tile' }" onclick="{!c.onBoatClick}">
        <div style="{!'background-image:URL(\'+v.boat.Picture__c+'\')'}" class="innertile">
              <div class="lower-third">
                   <h1 class="slds-truncate">{!v.boat.Contact__r.Name}</h1>
              </div>
        </div>
    </lightning:button> -->
    

    <lightning:button class="{!v.selected ? 'tile selected' : 'tile'}" onclick="{!c.onBoatClick}">

        <div style="{!'background-image: url(\'' + v.boat.Picture__c + '\')'}" class="innertile">

            <div class="lower-third">

                <h1 class="slds-truncate">{!v.boat.Contact__r.Name}</h1>

            </div>

        </div>

    </lightning:button>
    
</aura:component>



BoatTileController.js

onBoatClick : function(component, event, helper) {
        var eve = component.getEvent("BoatSelect");
        console.log('component.get("v.boat.Id")>>>'+component.get("v.boat.Id"));
        eve.setParams({"boatId" : component.get("v.boat.Id")});
        eve.fire();
        var appeve = $A.get("e.c:BoatSelected");
        console.log('component.get("v.boat") Application eve fire'+component.get("v.boat"));
        appeve.setParams({"boat" : component.get("v.boat")});
        appeve.fire();
    }

BoatDetails.cmp

<aura:component access="global" implements="force:appHostable,flexipage:availableForAllPageTypes">
    
    <aura:handler event="c:BoatSelected" action="c.onBoatSelected" phase="capture"/>
    
    <aura:attribute name="boat" type="Boat__c" access="public"/>
    <aura:attribute name="id" type="Id" access="public"/>
    <aura:attribute name="boatError" type="String"/>
    
    <force:recordData aura:id="service" recordId="{!v.id}" targetFields="{!v.boat}" fields="Id,Name,Description__c,Price__c,
                    Length__c,Contact__r.Name,Contact__r.Email,Contact__r.HomePhone,BoatType__r.Name,Picture__c"
                      targetError="{!v.boatError}" recordUpdated="{!c.onRecordUpdated}"/>
    
    <lightning:tabset >
        <lightning:tab label="Details">
            <aura:if isTrue="{! !empty(v.boat)}">
            <c:BoatDetail boat="{!v.boat}"/>
            </aura:if>
        </lightning:tab>

        <lightning:tab label="Reviews">

            

        </lightning:tab>
        
        <lightning:tab label="Add Review">

            

        </lightning:tab>

    </lightning:tabset>

</aura:component>

BoatDetailsController.js

onBoatSelected : function(component, event, helper) {
        var boatvar = event.getParam("boat");
        console.log(boatvar.Id+'<<<<<<Application Eve Receiver boatVar');
        component.set("v.id",boatvar.Id);
        console.log(component.get("v.id")+'<<<<<<Application Eve Receiver boatVar');
        component.find("service").reloadRecord(true);
        for(var i=0;i<1000;i++)
            {
                
            }
        console.log(component.get("v.boat")+'<<<<<<Application Eve Receiver');
        
    },
    
    onRecordUpdated : function(component, event, helper) {
    }
I working on the Trail Head module Quick Start: Lightning Components, the first topic - Enable Lightning Components, I change the domain name for TP and now I am not able to login to my TP as the domain got changed. On Launch of TP its gives following error  -

404
TRAIL NOT FOUND
Sorry, that page doesn't exist. Try retracing your steps or review the URL.
Hi,
I am facing issue with challenge 6 it gives error as in below screenshot

User-added image
 

I don't understand I have created the onBoatSelected controller function to run when BoatSelected application event is fired...but still I am getting this error. I have checked console log and I am getting all the boat details in my BoatDetails component. Below is my code -

BoatTile.cmp

<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes" access="global">
    <aura:attribute name="boat" type="Boat__C"/>
    <aura:attribute name="selected" type="Boolean"/>
    <aura:registerEvent name="BoatSelect" type="c:BoatSelect"/>
    <aura:registerEvent name="BoatSelected" type="c:BoatSelected"/>
    <!--<lightning:button class="tile{! v.selected ? 'selected' : 'tile' }" onclick="{!c.onBoatClick}">
        <div style="{!'background-image:URL(\'+v.boat.Picture__c+'\')'}" class="innertile">
              <div class="lower-third">
                   <h1 class="slds-truncate">{!v.boat.Contact__r.Name}</h1>
              </div>
        </div>
    </lightning:button> -->
    

    <lightning:button class="{!v.selected ? 'tile selected' : 'tile'}" onclick="{!c.onBoatClick}">

        <div style="{!'background-image: url(\'' + v.boat.Picture__c + '\')'}" class="innertile">

            <div class="lower-third">

                <h1 class="slds-truncate">{!v.boat.Contact__r.Name}</h1>

            </div>

        </div>

    </lightning:button>
    
</aura:component>



BoatTileController.js

onBoatClick : function(component, event, helper) {
        var eve = component.getEvent("BoatSelect");
        console.log('component.get("v.boat.Id")>>>'+component.get("v.boat.Id"));
        eve.setParams({"boatId" : component.get("v.boat.Id")});
        eve.fire();
        var appeve = $A.get("e.c:BoatSelected");
        console.log('component.get("v.boat") Application eve fire'+component.get("v.boat"));
        appeve.setParams({"boat" : component.get("v.boat")});
        appeve.fire();
    }

BoatDetails.cmp

<aura:component access="global" implements="force:appHostable,flexipage:availableForAllPageTypes">
    
    <aura:handler event="c:BoatSelected" action="c.onBoatSelected" phase="capture"/>
    
    <aura:attribute name="boat" type="Boat__c" access="public"/>
    <aura:attribute name="id" type="Id" access="public"/>
    <aura:attribute name="boatError" type="String"/>
    
    <force:recordData aura:id="service" recordId="{!v.id}" targetFields="{!v.boat}" fields="Id,Name,Description__c,Price__c,
                    Length__c,Contact__r.Name,Contact__r.Email,Contact__r.HomePhone,BoatType__r.Name,Picture__c"
                      targetError="{!v.boatError}" recordUpdated="{!c.onRecordUpdated}"/>
    
    <lightning:tabset >
        <lightning:tab label="Details">
            <aura:if isTrue="{! !empty(v.boat)}">
            <c:BoatDetail boat="{!v.boat}"/>
            </aura:if>
        </lightning:tab>

        <lightning:tab label="Reviews">

            

        </lightning:tab>
        
        <lightning:tab label="Add Review">

            

        </lightning:tab>

    </lightning:tabset>

</aura:component>

BoatDetailsController.js

onBoatSelected : function(component, event, helper) {
        var boatvar = event.getParam("boat");
        console.log(boatvar.Id+'<<<<<<Application Eve Receiver boatVar');
        component.set("v.id",boatvar.Id);
        console.log(component.get("v.id")+'<<<<<<Application Eve Receiver boatVar');
        component.find("service").reloadRecord(true);
        for(var i=0;i<1000;i++)
            {
                
            }
        console.log(component.get("v.boat")+'<<<<<<Application Eve Receiver');
        
    },
    
    onRecordUpdated : function(component, event, helper) {
    }
I've gone through every step successfully but am banging my head against the wall with step 8. I have more than adequate code coverage but continue to get this error message:
User-added image
I have gone back and rewritten OrderTests twice according to the requirements but can't get past this error. Anyone else had any luck with this?

Here's my code for reference:
@isTest (SeeAllData=false)
private class OrderTests {
    
    static void SetupTestData() {
	    TestDataFactory.InsertTestData(5);
    }
 
    @isTest static void OrderExtension_UnitTest() {
        PageReference pageRef = Page.OrderEdit;
        Test.setCurrentPage(pageRef);
        SetupTestData();
        ApexPages.StandardController stdcontroller = new ApexPages.StandardController(TestDataFactory.orders[0]);        
        OrderExtension ext = new OrderExtension(stdcontroller);        
       	System.assertEquals(Constants.DEFAULT_ROWS, ext.orderItemList.size());
        ext.OnFieldChange();
        ext.SelectFamily();
        ext.Save();
        ext.First();
        ext.Next();
        ext.Previous();
        ext.Last();
        ext.GetHasPrevious();
        ext.GetHasNext();
        ext.GetTotalPages();
        ext.GetPageNumber();
        List<SelectOption> options = ext.GetFamilyOptions();
    }
    
@isTest
public static void OrderUpdate_UnitTest(){
    setupTestData();
    
   
    Test.startTest();
    
    List<Order> orders = TestDataFactory.orders;
    for (Order o : orders){
        o.Status = Constants.ACTIVATED_ORDER_STATUS;
    }
    List<Product2> oldProducts = TestDataFactory.products;
    Set<Id> productIds = new Set<Id>();
    for (Product2 oldProd : oldProducts){
        productIds.add(oldProd.Id);
    }
    oldProducts = [SELECT Id, Quantity_Ordered__c FROM Product2 WHERE ID IN :productIds];
    Map<Id, Integer> quantities = new Map<Id, Integer>();
    for (OrderItem oi : TestDataFactory.orderItems){
        Integer quantity = 0;
        List<PricebookEntry> pricebookentries = TestDataFactory.pbes;
        for (PricebookEntry pbe : pricebookentries){
            if (oi.PricebookEntryId == pbe.Id){                
                if (quantities.containsKey(pbe.Product2Id)){
                    quantity = quantities.get(pbe.Product2Id);
                }
                quantity += (Integer)oi.Quantity;
                quantities.put(pbe.Product2Id, quantity);
                break;
            }
        }
    }
   
    update orders;
    Map<Id, Product2> currentProducts = new Map<Id, Product2>([Select Id, Quantity_Ordered__c FROM Product2 WHERE Id IN :productIds]);
  
    for (Product2 prod : oldProducts){
      
        TestDataFactory.VerifyQuantityOrdered(prod, currentProducts.get(prod.Id), quantities.get(prod.Id));
  }
  Test.stopTest();
}
}

 
I am getting below error
User-added image

but my application has 
User-added image

May I know why am not able to pass this challenge ?