• Peter McGavin
  • NEWBIE
  • 60 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 8
    Questions
  • 13
    Replies
Hi,

I have managed to get the challenge working but the trailhaed keeps displaying the following message when I press the Check challgene button:
The campingList component isn't iterating the array of 'items' and creating 'campingListItem' components.

It could possibly be the way I have written the code (as separate components) compared to what the trailhead is expecting:

Here is my code:

a) harnessApp.app

<aura:application extends="force:slds">
    <c:campingHeader />
    <c:campingList />

</aura:application>
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

b) campingHeader.cmp

<aura:component >
    <!--<h1>Camping List</h1>-->
<!-- PAGE HEADER -->
    <lightning:layout class="slds-page-header slds-page-header--object-home">
        <lightning:layoutItem >
            <lightning:icon iconName="action:goal" alternativeText="Camping List"/>
        </lightning:layoutItem>
        <lightning:layoutItem padding="horizontal-small">
            <div class="page-section page-header">
                <h1 class="slds-text-heading--label">Camping Item</h1>
                <h2 class="slds-text-heading--medium">My Camping Items</h2>
            </div>
        </lightning:layoutItem>
    </lightning:layout>
    <!-- / PAGE HEADER -->
    
</aura:component>

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
c) campingList.cmp

<aura:component >
    
    <aura:attribute name="items" type="Camping_Item__c[]"/>
    
    <aura:attribute name="newItem" type="Camping_Item__c"
     default="{ 'sobjectType': 'Camping_Item__c',
                    'Name': '',
                    'Packed__c': '',
                    'Price__c': '0',
                    'Quantity__c': '0' }"/>
    
    <!-- NEW CAMPING ITEM FORM -->
    <lightning:layout >
        <lightning:layoutItem padding="around-small" size="6">

        <!-- CREATE NEW CAMPING ITEM -->
    <div aria-labelledby="newcampingitemform">

    <!-- BOXED AREA -->
    <fieldset class="slds-box slds-theme--default slds-container--small">

    <legend id="newcampingitemform" class="slds-text-heading--small 
      slds-p-vertical--medium">
      Add Camping Item
    </legend>

    <!-- CREATE NEW CAMPING ITEM FORM -->
    <form class="slds-form--stacked">  
       
        <lightning:input aura:id="campingitemform" label="Item Name"
                         name="campingitemname"
                         value="{!v.newItem.Name}"
                         required="true"/> 
        
        <lightning:input type="number" aura:id="campingitemform" label="Quantity"
                         name="campingitemquantity"
                         min="1"
                         value="{!v.newItem.Quantity__c}"
                         messageWhenRangeUnderflow="Enter at least 1"/>
        
        <lightning:input type="number" aura:id="campingitemform" label="Price"
                         name="campingitemprice"
                         formatter="currency"
                         step="0.01"
                         value="{!v.newItem.Price__c}" />
        
        <lightning:input type="checkbox" aura:id="campingitemform" label="Packed?"  
                         name="campingitempacked"
                         checked="{!v.newItem.Packed__c}"/>
        
        <lightning:button label="Create Item" 
                          class="slds-m-top--medium"
                          variant="brand"
                          onclick="{!c.clickCreateItem}"/>
    </form>
    <!-- / CREATE NEW CAMPING ITEM FORM -->

  </fieldset>
  <!-- / BOXED AREA -->

</div>
<!-- / CREATE CAMPING NEW ITEM -->

        </lightning:layoutItem>
    </lightning:layout>
    <!-- / NEW CAMPING ITEM FORM -->
   
    <c:campingListItem items="{!v.items}"/>

  
</aura:component>
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

d) campingListController.js

({
    clickCreateItem: function(component, event, helper) {
        var validItem = component.find('campingitemform').reduce(function (validSoFar, inputCmp) {
            // Displays error messages for invalid fields
            inputCmp.showHelpMessageIfInvalid();
            return validSoFar && inputCmp.get('v.validity').valid;
        }, true);
        // If we pass error checking, do some real work
        if(validItem){
            // Create the new expense
            var newItem = component.get("v.newItem");
            console.log("Create item: " + JSON.stringify(newItem));
            helper.createItem(component, newItem);
        }
   
    }
 
})
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

e) campingListHelper.js

({createItem: function(component, item) {
        var theItem = component.get("v.items");
 
        // Copy the expense to a new object
        // THIS IS A DISGUSTING, TEMPORARY HACK
        var newItem = JSON.parse(JSON.stringify(item));
 
        console.log("Item before 'create': " + JSON.stringify(theItem));
        theItem.push(newItem);
        component.set("v.items", theItem);
        console.log("Item after 'create': " + JSON.stringify(theItem));
        component.set("v.newItem",{ 'sobjectType': 'Camping_Item__c',
                    'Name': '',
                    'Quantity__c': 0,
                    'Price__c': 0,
                    'Packed__c': false });
        }
 })
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

f) campingListItem.cmp

<aura:component >

    <aura:attribute name="items" type="Camping_Item__c[]"/>

    <lightning:card title="Items">
        <p class="slds-p-horizontal--small">
            <aura:iteration items="{!v.items}" var="item">
                <c:campingListItems item="{!item}"/>
            </aura:iteration>
        </p>
    </lightning:card>
    
</aura:component>
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

g) campingListItems.cmp

<aura:component >
    <aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
    <!--aura:attribute name="formatdate" type="Date"/-->
    <aura:attribute name="item" type="Camping_Item__c"/>


    <lightning:card title="{!v.item.Name}" iconName="standard:scan_card"
                    class="{!v.item.Packed__c ?
                           'slds-theme--success' : ''}">
        <aura:set attribute="footer">
            <!--p>Date: <lightning:formattedDateTime value="{!v.formatdate}"/></p-->
            <!--p class="slds-text-title"><lightning:relativeDateTime value="{!v.formatdate}"/></p-->
        </aura:set>
        
        <p class="slds-p-horizontal--small">
            Quantity: {!v.item.Quantity__c}
        </p>
        
        <p class="slds-text-heading--medium slds-p-horizontal--small">
           Price: <lightning:formattedNumber value="{!v.item.Price__c}" style="currency"/>
        </p>

        <p>
            <lightning:input type="toggle" 
                             label="Packed?"
                             name="packed"
                             class="slds-p-around--small"
                             checked="{!v.item.Packed__c}"
                             messageToggleActive="Yes"
                             messageToggleInactive="No"
                             onchange="{!c.clickPacked}"/>
        </p>
    </lightning:card>
</aura:component>
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Thanks in advance for your assistance on this. 


 
Hi,
I am stuck on the Atttributes and Expressions challenge of the lightening component basics:

I get the following message: The Name field is not being displayed using an expression.

I'm really not 100% sure how the display component is meant to work for Name and Packed status - as there seems to be no "<lightening: /> formatting markup available. 

Here is my code:

<aura:component>

    <aura:attribute name="item" type="Camping_Item__c" required="true" />

    <aura:attribute name="expense" type="Expense__c"/>
    
    <p>Name: 
        <lightning:String value="{!v.item.Name__c}" style="Text"/>
    </p>
    
    <p>Price:
        <lightning:formattedNumber value="{!v.item.Price__c}" style="Currency"/>
    </p>
    
    <p>Quantity:
        <lightning:formattedNumber value="{!v.item.Quantity__c}" style="Number"/>
    </p>
    
    <p>Packed Status:
        <lightning:Checkbox value="{!v.item.Packed__c}" style="Toggle"/>
    </p>

</aura:component>

Thanks for your assistance in advance.
I cannot complete the Subscribe to Platform Events challenge. When I click the 'Check Challenge' button I get the following error:

Publishing an Order_Event__e did not create the associated task successfully. Please check your trigger and event.

Here is my code:

trigger OrderEventTrigger on Order_Event__e (after insert) {
    // List to hold all tasks to be created.
    List<Task> tasks = new List<Task>();
    
    // Get queue Id for case owner
    String usr = UserInfo.getUserId(); 
        
       
    // Iterate through each notification.
    for (Order_Event__e event : Trigger.New) {
        if (event.Has_Shipped__c == true) {
            // Create Task to dispatch new team.
            Task t = new Task();
            t.Priority = 'Medium';
            t.Status = 'New';
            t.Subject = 'Follow up on shipped order' + event.Order_Number__c;
            t.OwnerId = Usr;
            tasks.add(t);
        }
   }
    
    // Insert all tasks corresponding to events received.
    insert tasks;
}

Please assist. Thanks. 
Hi,

I keep getting the following compile error:

Class LeadProcessor must implement the method: void Database.Batchable<SObject>.execute(Database.BatchableContext, List<SObject>)

FYI, here is my class code:

global class LeadProcessor implements Database.Batchable<Sobject>
    {    

    global Database.QueryLocator start(Database.BatchableContext bc) 
    {
        return Database.getQueryLocator([SELECT LeadSource FROM Lead]);
    }

    global void execute(Database.BatchableContext bc, List<Leads> scope){
        // process each batch of records
        for (Leads l: scope) {
             l.LeadSource = 'Dreamforce';
             recordsProcessed = recordsProcessed + 1;
            }
        update scope;
    }    

    global void finish(Database.BatchableContext bc){}    
}

Please assist. Thanks

 
Hi,

I am getting the error: 09:59:02:052 FATAL_ERROR System.QueryException: List has no rows for assignment to SObject when trying to complete the Apex Web services challenge.

Here is my code:

a) AccountManager class:
====================

@RestResource(urlMapping='/Accounts/*/Contacts')
global class AccountManager {
    @HttpGet
    global static Account getAccount() {
        RestRequest request = RestContext.request;
        String AccId = request.requestURI.substringBetween('/Accounts/' , '/Contacts');
        Account result =  [SELECT Id, Name, (Select Id, Name from Contacts) FROM Account WHERE Id = :AccId];
        return result;
    }
}


b) AccountManagerTest:
===================
@isTest
private class AccountManagerTest {

    private static testMethod void getAccountTest1() {
        Id recordId = createTestRecord();
        System.debug('record id = ' + recordId);
        // Set up a test request
        RestRequest request = new RestRequest();
        request.requestUri = 'https://cunning-bear-27155-dev-ed.my.salesforce.com/services/apexrest/Accounts/'+ recordId +'/contacts' ;
        request.httpMethod = 'GET';
        RestContext.request = request;
        // Call the method to test
        Account thisAccount = AccountManager.getAccount();
        // Verify results
        System.assert(thisAccount != null);
        System.assertEquals('Test record', thisAccount.Name);
        
    }

    // Helper method
    static Id createTestRecord() {
        // Create test record
        Account TestAcc = new Account(
            Name='Test record');
        insert TestAcc;
        Contact TestCon= new Contact(
            LastName='Test', 
            AccountId = Testacc.id);
        insert TestCon;
        return TestAcc.Id;
    }      
}
 
Hi,
The trailhead challenge for Admin Advanced  Advanced Formulas (Level Up with Advanced Formulas) states:
Create a formula that shows where an Opportunity is in the pipeline.
Create a formula field that classifies an Opportunity as either “Early”, “Middle”, or “Late”. This formula field should use TODAY() to calculate what percentage of the time between an opportunity’s CreatedDate and CloseDate has passed, and label the opportunity accordingly.

My question is where is the createdDate field in the oppotunities object? The challenge implies this is an existing field but I cannot find it. 
Also what is meant by percentage of time passed in this context? Does this mean 'the time passed between the createdDate and closedDate' in relation to (i.e. divided by) 'the time passed between the createdDate and TODAY' ? 

Thanks in advance.

CASE( MOD(TODAY() - DATE(1900, 1, 7), 7),
3, TODAY() + 2 + 3,
4, TODAY() + 2 + 3,
5, TODAY() + 2 + 3,
6, TODAY() + 1 + 3,
TODAY() + 3 )
Hi,

I have managed to get the challenge working but the trailhaed keeps displaying the following message when I press the Check challgene button:
The campingList component isn't iterating the array of 'items' and creating 'campingListItem' components.

It could possibly be the way I have written the code (as separate components) compared to what the trailhead is expecting:

Here is my code:

a) harnessApp.app

<aura:application extends="force:slds">
    <c:campingHeader />
    <c:campingList />

</aura:application>
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

b) campingHeader.cmp

<aura:component >
    <!--<h1>Camping List</h1>-->
<!-- PAGE HEADER -->
    <lightning:layout class="slds-page-header slds-page-header--object-home">
        <lightning:layoutItem >
            <lightning:icon iconName="action:goal" alternativeText="Camping List"/>
        </lightning:layoutItem>
        <lightning:layoutItem padding="horizontal-small">
            <div class="page-section page-header">
                <h1 class="slds-text-heading--label">Camping Item</h1>
                <h2 class="slds-text-heading--medium">My Camping Items</h2>
            </div>
        </lightning:layoutItem>
    </lightning:layout>
    <!-- / PAGE HEADER -->
    
</aura:component>

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
c) campingList.cmp

<aura:component >
    
    <aura:attribute name="items" type="Camping_Item__c[]"/>
    
    <aura:attribute name="newItem" type="Camping_Item__c"
     default="{ 'sobjectType': 'Camping_Item__c',
                    'Name': '',
                    'Packed__c': '',
                    'Price__c': '0',
                    'Quantity__c': '0' }"/>
    
    <!-- NEW CAMPING ITEM FORM -->
    <lightning:layout >
        <lightning:layoutItem padding="around-small" size="6">

        <!-- CREATE NEW CAMPING ITEM -->
    <div aria-labelledby="newcampingitemform">

    <!-- BOXED AREA -->
    <fieldset class="slds-box slds-theme--default slds-container--small">

    <legend id="newcampingitemform" class="slds-text-heading--small 
      slds-p-vertical--medium">
      Add Camping Item
    </legend>

    <!-- CREATE NEW CAMPING ITEM FORM -->
    <form class="slds-form--stacked">  
       
        <lightning:input aura:id="campingitemform" label="Item Name"
                         name="campingitemname"
                         value="{!v.newItem.Name}"
                         required="true"/> 
        
        <lightning:input type="number" aura:id="campingitemform" label="Quantity"
                         name="campingitemquantity"
                         min="1"
                         value="{!v.newItem.Quantity__c}"
                         messageWhenRangeUnderflow="Enter at least 1"/>
        
        <lightning:input type="number" aura:id="campingitemform" label="Price"
                         name="campingitemprice"
                         formatter="currency"
                         step="0.01"
                         value="{!v.newItem.Price__c}" />
        
        <lightning:input type="checkbox" aura:id="campingitemform" label="Packed?"  
                         name="campingitempacked"
                         checked="{!v.newItem.Packed__c}"/>
        
        <lightning:button label="Create Item" 
                          class="slds-m-top--medium"
                          variant="brand"
                          onclick="{!c.clickCreateItem}"/>
    </form>
    <!-- / CREATE NEW CAMPING ITEM FORM -->

  </fieldset>
  <!-- / BOXED AREA -->

</div>
<!-- / CREATE CAMPING NEW ITEM -->

        </lightning:layoutItem>
    </lightning:layout>
    <!-- / NEW CAMPING ITEM FORM -->
   
    <c:campingListItem items="{!v.items}"/>

  
</aura:component>
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

d) campingListController.js

({
    clickCreateItem: function(component, event, helper) {
        var validItem = component.find('campingitemform').reduce(function (validSoFar, inputCmp) {
            // Displays error messages for invalid fields
            inputCmp.showHelpMessageIfInvalid();
            return validSoFar && inputCmp.get('v.validity').valid;
        }, true);
        // If we pass error checking, do some real work
        if(validItem){
            // Create the new expense
            var newItem = component.get("v.newItem");
            console.log("Create item: " + JSON.stringify(newItem));
            helper.createItem(component, newItem);
        }
   
    }
 
})
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

e) campingListHelper.js

({createItem: function(component, item) {
        var theItem = component.get("v.items");
 
        // Copy the expense to a new object
        // THIS IS A DISGUSTING, TEMPORARY HACK
        var newItem = JSON.parse(JSON.stringify(item));
 
        console.log("Item before 'create': " + JSON.stringify(theItem));
        theItem.push(newItem);
        component.set("v.items", theItem);
        console.log("Item after 'create': " + JSON.stringify(theItem));
        component.set("v.newItem",{ 'sobjectType': 'Camping_Item__c',
                    'Name': '',
                    'Quantity__c': 0,
                    'Price__c': 0,
                    'Packed__c': false });
        }
 })
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

f) campingListItem.cmp

<aura:component >

    <aura:attribute name="items" type="Camping_Item__c[]"/>

    <lightning:card title="Items">
        <p class="slds-p-horizontal--small">
            <aura:iteration items="{!v.items}" var="item">
                <c:campingListItems item="{!item}"/>
            </aura:iteration>
        </p>
    </lightning:card>
    
</aura:component>
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

g) campingListItems.cmp

<aura:component >
    <aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
    <!--aura:attribute name="formatdate" type="Date"/-->
    <aura:attribute name="item" type="Camping_Item__c"/>


    <lightning:card title="{!v.item.Name}" iconName="standard:scan_card"
                    class="{!v.item.Packed__c ?
                           'slds-theme--success' : ''}">
        <aura:set attribute="footer">
            <!--p>Date: <lightning:formattedDateTime value="{!v.formatdate}"/></p-->
            <!--p class="slds-text-title"><lightning:relativeDateTime value="{!v.formatdate}"/></p-->
        </aura:set>
        
        <p class="slds-p-horizontal--small">
            Quantity: {!v.item.Quantity__c}
        </p>
        
        <p class="slds-text-heading--medium slds-p-horizontal--small">
           Price: <lightning:formattedNumber value="{!v.item.Price__c}" style="currency"/>
        </p>

        <p>
            <lightning:input type="toggle" 
                             label="Packed?"
                             name="packed"
                             class="slds-p-around--small"
                             checked="{!v.item.Packed__c}"
                             messageToggleActive="Yes"
                             messageToggleInactive="No"
                             onchange="{!c.clickPacked}"/>
        </p>
    </lightning:card>
</aura:component>
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Thanks in advance for your assistance on this. 


 
Hi,
I am stuck on the Atttributes and Expressions challenge of the lightening component basics:

I get the following message: The Name field is not being displayed using an expression.

I'm really not 100% sure how the display component is meant to work for Name and Packed status - as there seems to be no "<lightening: /> formatting markup available. 

Here is my code:

<aura:component>

    <aura:attribute name="item" type="Camping_Item__c" required="true" />

    <aura:attribute name="expense" type="Expense__c"/>
    
    <p>Name: 
        <lightning:String value="{!v.item.Name__c}" style="Text"/>
    </p>
    
    <p>Price:
        <lightning:formattedNumber value="{!v.item.Price__c}" style="Currency"/>
    </p>
    
    <p>Quantity:
        <lightning:formattedNumber value="{!v.item.Quantity__c}" style="Number"/>
    </p>
    
    <p>Packed Status:
        <lightning:Checkbox value="{!v.item.Packed__c}" style="Toggle"/>
    </p>

</aura:component>

Thanks for your assistance in advance.
I cannot complete the Subscribe to Platform Events challenge. When I click the 'Check Challenge' button I get the following error:

Publishing an Order_Event__e did not create the associated task successfully. Please check your trigger and event.

Here is my code:

trigger OrderEventTrigger on Order_Event__e (after insert) {
    // List to hold all tasks to be created.
    List<Task> tasks = new List<Task>();
    
    // Get queue Id for case owner
    String usr = UserInfo.getUserId(); 
        
       
    // Iterate through each notification.
    for (Order_Event__e event : Trigger.New) {
        if (event.Has_Shipped__c == true) {
            // Create Task to dispatch new team.
            Task t = new Task();
            t.Priority = 'Medium';
            t.Status = 'New';
            t.Subject = 'Follow up on shipped order' + event.Order_Number__c;
            t.OwnerId = Usr;
            tasks.add(t);
        }
   }
    
    // Insert all tasks corresponding to events received.
    insert tasks;
}

Please assist. Thanks. 
Hi,

I keep getting the following compile error:

Class LeadProcessor must implement the method: void Database.Batchable<SObject>.execute(Database.BatchableContext, List<SObject>)

FYI, here is my class code:

global class LeadProcessor implements Database.Batchable<Sobject>
    {    

    global Database.QueryLocator start(Database.BatchableContext bc) 
    {
        return Database.getQueryLocator([SELECT LeadSource FROM Lead]);
    }

    global void execute(Database.BatchableContext bc, List<Leads> scope){
        // process each batch of records
        for (Leads l: scope) {
             l.LeadSource = 'Dreamforce';
             recordsProcessed = recordsProcessed + 1;
            }
        update scope;
    }    

    global void finish(Database.BatchableContext bc){}    
}

Please assist. Thanks

 
Hi,

I am getting the error: 09:59:02:052 FATAL_ERROR System.QueryException: List has no rows for assignment to SObject when trying to complete the Apex Web services challenge.

Here is my code:

a) AccountManager class:
====================

@RestResource(urlMapping='/Accounts/*/Contacts')
global class AccountManager {
    @HttpGet
    global static Account getAccount() {
        RestRequest request = RestContext.request;
        String AccId = request.requestURI.substringBetween('/Accounts/' , '/Contacts');
        Account result =  [SELECT Id, Name, (Select Id, Name from Contacts) FROM Account WHERE Id = :AccId];
        return result;
    }
}


b) AccountManagerTest:
===================
@isTest
private class AccountManagerTest {

    private static testMethod void getAccountTest1() {
        Id recordId = createTestRecord();
        System.debug('record id = ' + recordId);
        // Set up a test request
        RestRequest request = new RestRequest();
        request.requestUri = 'https://cunning-bear-27155-dev-ed.my.salesforce.com/services/apexrest/Accounts/'+ recordId +'/contacts' ;
        request.httpMethod = 'GET';
        RestContext.request = request;
        // Call the method to test
        Account thisAccount = AccountManager.getAccount();
        // Verify results
        System.assert(thisAccount != null);
        System.assertEquals('Test record', thisAccount.Name);
        
    }

    // Helper method
    static Id createTestRecord() {
        // Create test record
        Account TestAcc = new Account(
            Name='Test record');
        insert TestAcc;
        Contact TestCon= new Contact(
            LastName='Test', 
            AccountId = Testacc.id);
        insert TestCon;
        return TestAcc.Id;
    }      
}
 
Hi,
The trailhead challenge for Admin Advanced  Advanced Formulas (Level Up with Advanced Formulas) states:
Create a formula that shows where an Opportunity is in the pipeline.
Create a formula field that classifies an Opportunity as either “Early”, “Middle”, or “Late”. This formula field should use TODAY() to calculate what percentage of the time between an opportunity’s CreatedDate and CloseDate has passed, and label the opportunity accordingly.

My question is where is the createdDate field in the oppotunities object? The challenge implies this is an existing field but I cannot find it. 
Also what is meant by percentage of time passed in this context? Does this mean 'the time passed between the createdDate and closedDate' in relation to (i.e. divided by) 'the time passed between the createdDate and TODAY' ? 

Thanks in advance.