• Jeff Hansen
  • NEWBIE
  • 10 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 3
    Replies
I can not get past this error on this module in the Lightning Componet Basics in the developer intermediate trail.  The error is - The campingList JavaScript helper isn't saving the new record to the database or adding it to the 'items' value provider.  The frustrating thing is that records are actually being saved when i test it out with the harrness.app.  the fllowing is my code:
campingList.cmp -
<aura:component controller="CampingListController" >
    <aura:attribute name="items" type="Camping_Item__c[]" />
    <aura:attribute name="newItem" type="Camping_Item__c"
                    default="{ 'sobjectType': 'Camping_Item__c',
                    'Name': '',
                    'Quantity__c': 0,
                    'Price__c': 0}"/>
   
    <aura:handler name="init" action="{!c.doInit}" value="{!this}"/>
       
    <div aria-labelledby="newexpenseform">
    <fieldset class="slds-box slds-theme--default slds-container--small">
        <legend id="newexpenseform" class="slds-text-heading--small
      slds-p-vertical--medium">
      Add Item
    </legend>
    <form class="slds-form--stacked">
     <div class="slds-form-element slds-is-required">
          <div class="slds-form-element__control">
              <ui:inputText aura:id="itemName" label="Camping Item Name"
                  class="slds-input"
                  labelClass="slds-form-element__label"
                  value="{!v.newItem.Name}"
                  required="true"/>
          </div>
     </div>       
               
      <div class="slds-form-element slds-is-required">
          <div class="slds-form-element__control">
              <ui:inputNumber aura:id="itemQuantity" label="Camping Item Quantity"
                  class="slds-input"
                  labelClass="slds-form-element__label"
                  value="{!v.newItem.Quantity__c}"
                  required="true"/>
          </div>
     </div>
       
        <div class="slds-form-element slds-is-required">
          <div class="slds-form-element__control">
              <ui:inputCurrency aura:id="itemPrice" label="Camping Item Price"
                  class="slds-input"
                  labelClass="slds-form-element__label"
                  value="{!v.newItem.Price__c}"
                  required="true"/>
          </div>
     </div>
       
     <div class="slds-form-element slds-is-required">
          <div class="slds-form-element__control">
              <ui:inputCheckbox aura:id="itemPacked" label="Camping Item Packed"
                  class="slds-input"
                  labelClass="slds-form-element__label"
                  value="{!v.newItem.Packed__c}"
                  />
          </div>
     </div>

         <div class="slds-form-element">
          <ui:button label="Create Camping Item"
              class="slds-button slds-button--brand"
              press="{!c.clickCreateItem}"/>
      </div>       
       
        <section class="slds-card__body">
            <div id="list" class="row">
                <aura:iteration items="{!v.items}" var="it">
                    <c:campingListItem item="{!it}"/>
                    <br />
                </aura:iteration>
            </div>
        </section>
   
    </form>
    </fieldset>   
    </div>
     
</aura:component>


campingListController.js -
({ 
    doInit: function(component, event, helper) {

    // Create the action
    var action = component.get("c.getItems");

    // Add callback behavior for when response is received
    action.setCallback(this, function(response) {
        var state = response.getState();
        if (component.isValid() && state === "SUCCESS") {
            component.set("v.items", response.getReturnValue());
        }
        else {
            console.log("Failed with state: " + state);
        }
    });

    // Send action off to be executed
    $A.enqueueAction(action);
},
   
    clickCreateItem: function(component, event, helper) {
    if(helper.validateItemForm(component)){
       helper.createItem (component);
    }
}
       
})

campingListHelper.js -
({  
 createItem: function(component) {
    var action = component.get("c.saveItem");
    var it = component.get("v.newItem");
    action.setParams({"item": it});
         
    action.setCallback(this, function(response){
        var state = response.getState();
        if (component.isValid() && state === "SUCCESS") {
            var itm = component.get("v.items");
            itm.push(response.getReturnValue());
            component.set("v.items", itm);           
        }
    });
    $A.enqueueAction(action);
},
   
 validateItemForm : function(component){
         var validItem = true;
       
        var namefield = component.find("itemName");
        var iname = namefield.get("v.value");
        if($A.util.isEmpty(iname)){
             validItem = false;
             namefield.set("v.errors", [{message:"Item name can't be blank."}]);
        }else{
             namefield.set("v.errors", null);
        }
       
           var iQuantity = component.find("itemQuantity");
        var iquan = iQuantity.get("v.value");
        if($A.util.isEmpty(iquan)){
             validItem = false;
             iQuantity.set("v.errors", [{message:"Item Quantity can't be blank."}]);
        }else{
             iQuantity.set("v.errors", null);
        }
               
              var iPrice = component.find("itemPrice");
        var ipri = iPrice.get("v.value");
        if($A.util.isEmpty(ipri)){
             validItem = false;
             iPrice.set("v.errors", [{message:"Item price can't be blank."}]);
        }else{
              iPrice.set("v.errors", null);
        }
       
        return validItem;
    } 
   
})


CampingListController.apxc -
public class CampingListController {

     @AuraEnabled
    public static Camping_Item__c saveItem (Camping_Item__c item) {
        // Perform isUpdatable() checking first, then
        upsert item;
        return item;
    }
   
   
    @AuraEnabled
    public static List<Camping_Item__c> getItems() {
        // Perform isAccessible() checking first, then
        return [SELECT Id, Name, Packed__c, Price__c, Quantity__c
                FROM Camping_Item__c];
    }
   
  
}


Any help would be greatly appreciated!
Thanks!

 
I'm going through this trail and I have gotten stuck on the Handle acitons with controllers module in the first section in the intermeidate developer trail. I am stuck onthe chalange for this module. The error i have not been able to get past is this: The campingListItem Lightning Component doesn't contain a button or its attributes are not set correctly when clicked.
I know the code i have now is not perfect, i have been messing with it trying everything i can think of for hours now. at this point this is what i have:
<aura:component >
    <aura:attribute name="item" type="Camping_Item__c" />
  
     <aura:attribute name="buttonDisabled" type="String" default="false"/>
   
    <ui:outputText value="{! v.item.name}"  />
     <ui:outputCheckbox value="{!v.item.Packed__c}"/>
     <ui:outputCurrency value="{!v.item.Price__c}"/>
     <ui:outputNumber value="{! v.item.Quantity__c}"  />
    <ui:button  label="Mark as packed" press="{!c.packItem}" disabled="{! v.buttonDisabled}" />
     
</aura:component>


and JS of
({
 packItem  : function(component, event, helper) {
      //component.set("v.item.Packed__c", true);      
       
       component.set("v.buttonDisabled", "true");         
 }
})


the one line is commented out because i was trying to just focus and get past this one error.
I just can't seem to figure out how the challenge want me to disable the button. very frustrating when the module doesn't give an example of how to do this and the challenge expects you to figure it out. I've looked at all the additional resources for the module and looked in forms and google, and i guess this is my last hope. otherwise I guess I'll have to skip this challenge...
Thanks for any help.
 
I can not get past this error on this module in the Lightning Componet Basics in the developer intermediate trail.  The error is - The campingList JavaScript helper isn't saving the new record to the database or adding it to the 'items' value provider.  The frustrating thing is that records are actually being saved when i test it out with the harrness.app.  the fllowing is my code:
campingList.cmp -
<aura:component controller="CampingListController" >
    <aura:attribute name="items" type="Camping_Item__c[]" />
    <aura:attribute name="newItem" type="Camping_Item__c"
                    default="{ 'sobjectType': 'Camping_Item__c',
                    'Name': '',
                    'Quantity__c': 0,
                    'Price__c': 0}"/>
   
    <aura:handler name="init" action="{!c.doInit}" value="{!this}"/>
       
    <div aria-labelledby="newexpenseform">
    <fieldset class="slds-box slds-theme--default slds-container--small">
        <legend id="newexpenseform" class="slds-text-heading--small
      slds-p-vertical--medium">
      Add Item
    </legend>
    <form class="slds-form--stacked">
     <div class="slds-form-element slds-is-required">
          <div class="slds-form-element__control">
              <ui:inputText aura:id="itemName" label="Camping Item Name"
                  class="slds-input"
                  labelClass="slds-form-element__label"
                  value="{!v.newItem.Name}"
                  required="true"/>
          </div>
     </div>       
               
      <div class="slds-form-element slds-is-required">
          <div class="slds-form-element__control">
              <ui:inputNumber aura:id="itemQuantity" label="Camping Item Quantity"
                  class="slds-input"
                  labelClass="slds-form-element__label"
                  value="{!v.newItem.Quantity__c}"
                  required="true"/>
          </div>
     </div>
       
        <div class="slds-form-element slds-is-required">
          <div class="slds-form-element__control">
              <ui:inputCurrency aura:id="itemPrice" label="Camping Item Price"
                  class="slds-input"
                  labelClass="slds-form-element__label"
                  value="{!v.newItem.Price__c}"
                  required="true"/>
          </div>
     </div>
       
     <div class="slds-form-element slds-is-required">
          <div class="slds-form-element__control">
              <ui:inputCheckbox aura:id="itemPacked" label="Camping Item Packed"
                  class="slds-input"
                  labelClass="slds-form-element__label"
                  value="{!v.newItem.Packed__c}"
                  />
          </div>
     </div>

         <div class="slds-form-element">
          <ui:button label="Create Camping Item"
              class="slds-button slds-button--brand"
              press="{!c.clickCreateItem}"/>
      </div>       
       
        <section class="slds-card__body">
            <div id="list" class="row">
                <aura:iteration items="{!v.items}" var="it">
                    <c:campingListItem item="{!it}"/>
                    <br />
                </aura:iteration>
            </div>
        </section>
   
    </form>
    </fieldset>   
    </div>
     
</aura:component>


campingListController.js -
({ 
    doInit: function(component, event, helper) {

    // Create the action
    var action = component.get("c.getItems");

    // Add callback behavior for when response is received
    action.setCallback(this, function(response) {
        var state = response.getState();
        if (component.isValid() && state === "SUCCESS") {
            component.set("v.items", response.getReturnValue());
        }
        else {
            console.log("Failed with state: " + state);
        }
    });

    // Send action off to be executed
    $A.enqueueAction(action);
},
   
    clickCreateItem: function(component, event, helper) {
    if(helper.validateItemForm(component)){
       helper.createItem (component);
    }
}
       
})

campingListHelper.js -
({  
 createItem: function(component) {
    var action = component.get("c.saveItem");
    var it = component.get("v.newItem");
    action.setParams({"item": it});
         
    action.setCallback(this, function(response){
        var state = response.getState();
        if (component.isValid() && state === "SUCCESS") {
            var itm = component.get("v.items");
            itm.push(response.getReturnValue());
            component.set("v.items", itm);           
        }
    });
    $A.enqueueAction(action);
},
   
 validateItemForm : function(component){
         var validItem = true;
       
        var namefield = component.find("itemName");
        var iname = namefield.get("v.value");
        if($A.util.isEmpty(iname)){
             validItem = false;
             namefield.set("v.errors", [{message:"Item name can't be blank."}]);
        }else{
             namefield.set("v.errors", null);
        }
       
           var iQuantity = component.find("itemQuantity");
        var iquan = iQuantity.get("v.value");
        if($A.util.isEmpty(iquan)){
             validItem = false;
             iQuantity.set("v.errors", [{message:"Item Quantity can't be blank."}]);
        }else{
             iQuantity.set("v.errors", null);
        }
               
              var iPrice = component.find("itemPrice");
        var ipri = iPrice.get("v.value");
        if($A.util.isEmpty(ipri)){
             validItem = false;
             iPrice.set("v.errors", [{message:"Item price can't be blank."}]);
        }else{
              iPrice.set("v.errors", null);
        }
       
        return validItem;
    } 
   
})


CampingListController.apxc -
public class CampingListController {

     @AuraEnabled
    public static Camping_Item__c saveItem (Camping_Item__c item) {
        // Perform isUpdatable() checking first, then
        upsert item;
        return item;
    }
   
   
    @AuraEnabled
    public static List<Camping_Item__c> getItems() {
        // Perform isAccessible() checking first, then
        return [SELECT Id, Name, Packed__c, Price__c, Quantity__c
                FROM Camping_Item__c];
    }
   
  
}


Any help would be greatly appreciated!
Thanks!

 
I'm going through this trail and I have gotten stuck on the Handle acitons with controllers module in the first section in the intermeidate developer trail. I am stuck onthe chalange for this module. The error i have not been able to get past is this: The campingListItem Lightning Component doesn't contain a button or its attributes are not set correctly when clicked.
I know the code i have now is not perfect, i have been messing with it trying everything i can think of for hours now. at this point this is what i have:
<aura:component >
    <aura:attribute name="item" type="Camping_Item__c" />
  
     <aura:attribute name="buttonDisabled" type="String" default="false"/>
   
    <ui:outputText value="{! v.item.name}"  />
     <ui:outputCheckbox value="{!v.item.Packed__c}"/>
     <ui:outputCurrency value="{!v.item.Price__c}"/>
     <ui:outputNumber value="{! v.item.Quantity__c}"  />
    <ui:button  label="Mark as packed" press="{!c.packItem}" disabled="{! v.buttonDisabled}" />
     
</aura:component>


and JS of
({
 packItem  : function(component, event, helper) {
      //component.set("v.item.Packed__c", true);      
       
       component.set("v.buttonDisabled", "true");         
 }
})


the one line is commented out because i was trying to just focus and get past this one error.
I just can't seem to figure out how the challenge want me to disable the button. very frustrating when the module doesn't give an example of how to do this and the challenge expects you to figure it out. I've looked at all the additional resources for the module and looked in forms and google, and i guess this is my last hope. otherwise I guess I'll have to skip this challenge...
Thanks for any help.
 
Hi,

I have written the below classes as part of the trailhead challenge for Apex REST callouts.

The class -

public class AnimalLocator {
  
  public static String getAnimalNameById(Integer id) {
    
    Http http = new Http();
    HttpRequest request = new HttpRequest();
    request.setEndpoint('https://th-apex-http-callout.herokuapp.com/animals/'+id);
    request.setMethod('GET');
    
    HttpResponse response = http.send(request);
    List<Object> animals; 
    String returnValue; 
    
    // parse the JSON response
    if (response.getStatusCode() == 200) {
      Map<String, Object> result = (Map<String, Object>) JSON.deserializeUntyped(response.getBody());
      animals = (List<Object>) result.get('animals');
      System.debug(animals);
    }
    
    if (animals.size() > 0 && animals != NULL && id < animals.size()) {
      returnValue = (String) animals.get(id);
    }
    
    return returnValue;
  } 
    
}

Mock Response Class - 

@isTest
global class AnimalLocatorMock implements HttpCalloutMock {
     // Implement this interface method
    global HTTPResponse respond(HTTPRequest request) {
        // Create a fake response
        HttpResponse response = new HttpResponse();
        response.setHeader('Content-Type', 'application/json');
        response.setBody('{"animals": ["majestic badger", "fluffy bunny", "scary bear", "chicken", "mighty moose"]}');
        response.setStatusCode(200);
        return response; 
    }
}

Test Class - 

@isTest
private class AnimalLocatorTest{
    @isTest static void AnimalLocatorMock1() {
        Test.setMock(HttpCalloutMock.class, new AnimalLocatorMock());
        string result = AnimalLocator.getAnimalNameById(3);
        String expectedResult = 'chicken';
        System.assertEquals(result,expectedResult );
    }
}

I have got 100% code coverage for the main class. But when I check the challenge I get 

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

Please tell me if any changes to the code is required. It's really frustrating as I am stuck from past 3-4 days with this unit.

Thanks & Regards,

Abhiram Sheshadri