• Jake Irvin
  • NEWBIE
  • 30 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 2
    Likes Received
  • 0
    Likes Given
  • 4
    Questions
  • 3
    Replies
I'm passing this challenge, however when I actually test it out by clicking on an account in the account list item, I get this exception: 

"Something has gone wrong. Action failed: c$AccountMap$controller$accountSelected [TypeError: Cannot read property 'reuseTiles' of undefined] Failing descriptor: {c$AccountMap$controller$accountSelected}."

I did some debugging and found that the location and latitude of the account are indeed being capture by my event, so it looks like this might be a problem with the leaflet function map.panTo(). Does anyone know the solution to this issue? Here's my code, although it's exactly the same as the tutorial's.
 
({
    jsLoaded: function(component, event, helper) {

        setTimeout(function() {
            var map = L.map('map', {zoomControl: false}).setView([37.784173, -122.401557], 14);
            L.tileLayer('https://server.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer/tile/{z}/{y}/{x}',
                {
                    attribution: 'Tiles © Esri'
                }).addTo(map);
            component.set("v.map", map);
        });
    },

    accountsLoaded: function(component, event, helper) {

        // Add markers
        var map = component.get('v.map');
        var accounts = event.getParam('accounts');
        for (var i=0; i<accounts.length; i++) {
            var account = accounts[i];
            var latLng = [account.Location__Latitude__s, account.Location__Longitude__s];
            L.marker(latLng, {account: account}).addTo(map);
        }  
    },

    accountSelected: function(component, event, helper) {
        // Center the map on the account selected in the list
        var map = component.get('v.map');
        var account = event.getParam("account");
        alert(account.Location__Latitude__s + ', ' + account.Location__Longitude__s);
        map.panTo([account.Location__Latitude__s, account.Location__Longitude__s]);
    }
})

 
I'm using the Salesforce IDE plugin in Eclipse, and I can't figure out how to create a test suite and add test classes to that suite. I can run individual test classes just fine though. Thanks in advance for you help!
My code works, but I'm still getting this error and I can't figure out why. I've looked around a lot on the forums but haven't found a solution that has worked for me. Here's the error:

"Challenge Not yet complete... here's what's wrong: The campingList JavaScript controller isn't setting the 'item' as a parameter or saving the record correctly."

Here's all my code:

Camping List.cmp
<aura:component controller="CampingListController">
    <aura:attribute name="items" type="Camping_Item__c[]"/>

    
    <aura:handler name="init" action="{!c.doInit}" value="{!this}"/>
    <aura:handler name="addItem" event="c:addItemEvent"
        action="{!c.handleAddItem}"/>
    
    <c:campingListForm />
    
        <div class="slds-card slds-p-top--medium">
        <header class="slds-card__header">
            <h3 class="slds-text-heading--small">Camping Items</h3>
        </header>
        
        <section class="slds-card__body">
            <div id="list" class="row">
                <aura:iteration items="{!v.items}" var="item">
                    <c:campingListItem item="{!item}"/>
                </aura:iteration>
            </div>
        </section>
    </div>
	
</aura:component>

CampingListController.js
({
    handleAddItem: function(component, event, helper) {
        var newItem = event.getParam("item");
        helper.createItem(component, newItem);
    }, 
    
    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);
    }
})


CampingListHelper.js
({
   createItem: function(component, item) {
        this.saveItem(component, item, function(response){
            var state = response.getState();
            if (component.isValid() && state === "SUCCESS") {
                var items = component.get("v.items");
                items.push(response.getReturnValue());
                component.set("v.items", items);
            }
        });
    },
    
    updateItem: function(component, item) {
        this.saveItem(component, item);
    },
    
    saveItem: function(component, item, callback) {
        var action = component.get("c.saveItem");
        console.log("Name of item to save: " + item.Name);
        action.setParams({
            "item": item
        });
        if (callback) {
            action.setCallback(this, callback);
        }
        console.log(action.getParam("item"));
        $A.enqueueAction(action);
    }
})

CampingListForm.cmp
<aura:component >
    <aura:registerEvent name="addItem" type="c:addItemEvent"/>
    
    <aura:attribute name="newItem" type="Camping_Item__c"
                    default="{ 'sobjectType': 'Camping_Item__c',
                             'Name': '',
                             'Quantity__c': 0,
                             'Price__c': 0,
                             'Packed__c': false }"/>

	<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="quantity" label="Quantity"
                  class="slds-input"
                  labelClass="slds-form-element__label"
                  value="{!v.newItem.Quantity__c}"
                  required="true"/>

          </div>
      </div>

      <div class="slds-form-element">
          <div class="slds-form-element__control">
              <ui:inputCurrency aura:id="price" label="Price"
                  class="slds-input"
                  labelClass="slds-form-element__label"
                  value="{!v.newItem.Price__c}"
                  />
          </div>
      </div>

      <div class="slds-form-element">
          <ui:inputCheckbox aura:id="packed" label="Packed?"
              class="slds-checkbox"
              labelClass="slds-form-element__label"
              value="{!v.newItem.Packed__c}"/>
      </div>

      <div class="slds-form-element">
          <ui:button label="Create Camping Item"
              class="slds-button slds-button--brand"
              press="{!c.clickCreateItem}"/>
      </div>
      
    </form>
</aura:component>

CampingListFormController.js
({
    clickCreateItem: function(component, event, helper) {
        if(helper.validateCampingListForm(component)){
            var newItem = component.get("v.newItem");
            helper.createItem(component, newItem);
        }
    }
})

CampingListFormHelper.js
({
	createItem: function(component, newItem) {
        var createEvent = component.getEvent("addItem");
        createEvent.setParams({ "item": newItem });
        createEvent.fire();
        component.set("v.newItem", 
                      {'sobjectType' : 'Camping_Item__c',
                       'Name' : '',
                       'Quantity__c' : 0,
                       'Price__c' : 0,
                       'Packed__c' : false});
    },
    
    validateCampingListForm: function(component) {
    
        // Simplistic error checking
        var validItem = true;
    
        // Name must not be blank
        var nameField = component.find("itemName");
        var name = nameField.get("v.value");
        console.log("Name: " + name);
        if ($A.util.isEmpty(name)){
            validItem = false;
            nameField.set("v.errors", [{message:"Expense name can't be blank."}]);
        }
        else {
            nameField.set("v.errors", null);
        }
    
        // Amount must be set, must be a positive number
        var quantityField = component.find("quantity");
        var quantity = quantityField.get("v.value");
        console.log("quantity: " + quantity);
        if ($A.util.isEmpty(quantity) || isNaN(quantity) || (quantity <= 0.0)){
            validItem = false;
            quantityField.set("v.errors", [{message:"Enter an quantity amount."}]);
        }
        else {
            // If the amount looks good, unset any errors...
            quantityField.set("v.errors", null);
        }
        
        var priceField = component.find("price");
        var price = priceField.get("v.value");
        console.log("price: " + price);

        if ($A.util.isEmpty(price) || isNaN(price) || (price <= 0.0)){
            validItem = false;
            priceField.set("v.errors", [{message:"Enter an price amount."}]);
        }
        else {
            // If the amount looks good, unset any errors...
            priceField.set("v.errors", null);
        }
        
        return(validItem);
    }
})

Thanks for your help!
I've been working on the trailhead training for apex triggers

However I keep getting an error in the developer console: "AccountAccess Trigger: Field is not writeable: Account.SippingAddress. I've scoured the forum but I haven't found anything that has been the answer to my problem. Thanks in advance for your help!
trigger AccountAddressTrigger on Account (before insert, before update) {
    for(Account a : Trigger.New) {
        if(NULL != a.BillingPostalCode && a.Match_Billing_Address__c == true){
			a.ShippingAddress = a.BillingAddress;
        }
    }
}

 
I'm passing this challenge, however when I actually test it out by clicking on an account in the account list item, I get this exception: 

"Something has gone wrong. Action failed: c$AccountMap$controller$accountSelected [TypeError: Cannot read property 'reuseTiles' of undefined] Failing descriptor: {c$AccountMap$controller$accountSelected}."

I did some debugging and found that the location and latitude of the account are indeed being capture by my event, so it looks like this might be a problem with the leaflet function map.panTo(). Does anyone know the solution to this issue? Here's my code, although it's exactly the same as the tutorial's.
 
({
    jsLoaded: function(component, event, helper) {

        setTimeout(function() {
            var map = L.map('map', {zoomControl: false}).setView([37.784173, -122.401557], 14);
            L.tileLayer('https://server.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer/tile/{z}/{y}/{x}',
                {
                    attribution: 'Tiles © Esri'
                }).addTo(map);
            component.set("v.map", map);
        });
    },

    accountsLoaded: function(component, event, helper) {

        // Add markers
        var map = component.get('v.map');
        var accounts = event.getParam('accounts');
        for (var i=0; i<accounts.length; i++) {
            var account = accounts[i];
            var latLng = [account.Location__Latitude__s, account.Location__Longitude__s];
            L.marker(latLng, {account: account}).addTo(map);
        }  
    },

    accountSelected: function(component, event, helper) {
        // Center the map on the account selected in the list
        var map = component.get('v.map');
        var account = event.getParam("account");
        alert(account.Location__Latitude__s + ', ' + account.Location__Longitude__s);
        map.panTo([account.Location__Latitude__s, account.Location__Longitude__s]);
    }
})

 
My code works, but I'm still getting this error and I can't figure out why. I've looked around a lot on the forums but haven't found a solution that has worked for me. Here's the error:

"Challenge Not yet complete... here's what's wrong: The campingList JavaScript controller isn't setting the 'item' as a parameter or saving the record correctly."

Here's all my code:

Camping List.cmp
<aura:component controller="CampingListController">
    <aura:attribute name="items" type="Camping_Item__c[]"/>

    
    <aura:handler name="init" action="{!c.doInit}" value="{!this}"/>
    <aura:handler name="addItem" event="c:addItemEvent"
        action="{!c.handleAddItem}"/>
    
    <c:campingListForm />
    
        <div class="slds-card slds-p-top--medium">
        <header class="slds-card__header">
            <h3 class="slds-text-heading--small">Camping Items</h3>
        </header>
        
        <section class="slds-card__body">
            <div id="list" class="row">
                <aura:iteration items="{!v.items}" var="item">
                    <c:campingListItem item="{!item}"/>
                </aura:iteration>
            </div>
        </section>
    </div>
	
</aura:component>

CampingListController.js
({
    handleAddItem: function(component, event, helper) {
        var newItem = event.getParam("item");
        helper.createItem(component, newItem);
    }, 
    
    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);
    }
})


CampingListHelper.js
({
   createItem: function(component, item) {
        this.saveItem(component, item, function(response){
            var state = response.getState();
            if (component.isValid() && state === "SUCCESS") {
                var items = component.get("v.items");
                items.push(response.getReturnValue());
                component.set("v.items", items);
            }
        });
    },
    
    updateItem: function(component, item) {
        this.saveItem(component, item);
    },
    
    saveItem: function(component, item, callback) {
        var action = component.get("c.saveItem");
        console.log("Name of item to save: " + item.Name);
        action.setParams({
            "item": item
        });
        if (callback) {
            action.setCallback(this, callback);
        }
        console.log(action.getParam("item"));
        $A.enqueueAction(action);
    }
})

CampingListForm.cmp
<aura:component >
    <aura:registerEvent name="addItem" type="c:addItemEvent"/>
    
    <aura:attribute name="newItem" type="Camping_Item__c"
                    default="{ 'sobjectType': 'Camping_Item__c',
                             'Name': '',
                             'Quantity__c': 0,
                             'Price__c': 0,
                             'Packed__c': false }"/>

	<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="quantity" label="Quantity"
                  class="slds-input"
                  labelClass="slds-form-element__label"
                  value="{!v.newItem.Quantity__c}"
                  required="true"/>

          </div>
      </div>

      <div class="slds-form-element">
          <div class="slds-form-element__control">
              <ui:inputCurrency aura:id="price" label="Price"
                  class="slds-input"
                  labelClass="slds-form-element__label"
                  value="{!v.newItem.Price__c}"
                  />
          </div>
      </div>

      <div class="slds-form-element">
          <ui:inputCheckbox aura:id="packed" label="Packed?"
              class="slds-checkbox"
              labelClass="slds-form-element__label"
              value="{!v.newItem.Packed__c}"/>
      </div>

      <div class="slds-form-element">
          <ui:button label="Create Camping Item"
              class="slds-button slds-button--brand"
              press="{!c.clickCreateItem}"/>
      </div>
      
    </form>
</aura:component>

CampingListFormController.js
({
    clickCreateItem: function(component, event, helper) {
        if(helper.validateCampingListForm(component)){
            var newItem = component.get("v.newItem");
            helper.createItem(component, newItem);
        }
    }
})

CampingListFormHelper.js
({
	createItem: function(component, newItem) {
        var createEvent = component.getEvent("addItem");
        createEvent.setParams({ "item": newItem });
        createEvent.fire();
        component.set("v.newItem", 
                      {'sobjectType' : 'Camping_Item__c',
                       'Name' : '',
                       'Quantity__c' : 0,
                       'Price__c' : 0,
                       'Packed__c' : false});
    },
    
    validateCampingListForm: function(component) {
    
        // Simplistic error checking
        var validItem = true;
    
        // Name must not be blank
        var nameField = component.find("itemName");
        var name = nameField.get("v.value");
        console.log("Name: " + name);
        if ($A.util.isEmpty(name)){
            validItem = false;
            nameField.set("v.errors", [{message:"Expense name can't be blank."}]);
        }
        else {
            nameField.set("v.errors", null);
        }
    
        // Amount must be set, must be a positive number
        var quantityField = component.find("quantity");
        var quantity = quantityField.get("v.value");
        console.log("quantity: " + quantity);
        if ($A.util.isEmpty(quantity) || isNaN(quantity) || (quantity <= 0.0)){
            validItem = false;
            quantityField.set("v.errors", [{message:"Enter an quantity amount."}]);
        }
        else {
            // If the amount looks good, unset any errors...
            quantityField.set("v.errors", null);
        }
        
        var priceField = component.find("price");
        var price = priceField.get("v.value");
        console.log("price: " + price);

        if ($A.util.isEmpty(price) || isNaN(price) || (price <= 0.0)){
            validItem = false;
            priceField.set("v.errors", [{message:"Enter an price amount."}]);
        }
        else {
            // If the amount looks good, unset any errors...
            priceField.set("v.errors", null);
        }
        
        return(validItem);
    }
})

Thanks for your help!
I've been working on the trailhead training for apex triggers

However I keep getting an error in the developer console: "AccountAccess Trigger: Field is not writeable: Account.SippingAddress. I've scoured the forum but I haven't found anything that has been the answer to my problem. Thanks in advance for your help!
trigger AccountAddressTrigger on Account (before insert, before update) {
    for(Account a : Trigger.New) {
        if(NULL != a.BillingPostalCode && a.Match_Billing_Address__c == true){
			a.ShippingAddress = a.BillingAddress;
        }
    }
}

 
<!--campingListItem.cmp-->
<aura:component >
	<aura:attribute name="item" type="Camping_Item__c" required="true"/>

	<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="Packed!" press="{!c.packItem}"/>
	
</aura:component>
<!--campingListController.js-->
({
	packItem : function(component, event, helper) {
		var button = event.getSource().get("v.disabled");
		component.set("v.item.Packed__c", "true");
		component.set(button, "true");
	}
})
What am I doing wrong?