2

I have been through several posts on workarounds to this issue where the code works, but the challenge is not passed, none of the proposed solutions seem to work for me:

https://d2hwpln2xvs3s.cloudfront.net/forums/?id=906F0000000kDmtIAE https://developer.salesforce.com/forums/?id=906F0000000kDPpIAM https://developer.salesforce.com/forums/?id=906F0000000kDPpIAM

in the last one Jeff Douglas seems to mention some code change/enhancement to the trailhead module.

Here is my handleAddItem function from the CampingListController.js:

    handleAddItem: function(component, event, helper) {
    var addItm = event.getParam("item");
    helper.createItem(component, addItm);

},

and createItem from the helper:

createItem: function(component, newItem) {
    var action = component.get("c.saveItem");
    action.setParams({
        "item": newItem
    });
    action.setCallback(this, 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);
            component.set("v.newItem",{'sobjectType':'Camping_Item__c',
                               'Name': '',
                               'Quantity__c': 0,
                               'Price__c': 0,
                               'Packed__c': false});
        }
    });
    $A.enqueueAction(action);

enter image description here

enter image description here

I posted the images of the rendered component after submitting the form and the record that is created from the apex method to the DB. Any idea why the challenge is not passed?

  • I am on this challenge right now. Did you create a lightning bundle or went with individual components? – abhi Jun 13 '17 at 19:12
10

I ended up moving the createItem function from my helper function to the CampingListController, since Trailhead does not "ask" us to split the createItem into a helper function.

handleAddItem: function(component, event, helper) {
    var addItm = event.getParam("item");
    helper.createItem(component, addItm);

},

    createItem: function(component, newItem) {
    var action = component.get("c.saveItem");
    action.setParams({
        "item": newItem
    });
    action.setCallback(this, 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);
        }
    });
    $A.enqueueAction(action);
},
  • 1
    would be great to fix this in trailhead – Donald Lobo Jun 6 '17 at 17:15
  • 1
    Really, I arrive at the same point, and moving the logic of the creation to the controller from the helper made it work, but somehow trailhead should not make those mandatory implementation restrictions. I spent more than an hour just not understanding why something functional and matching all described criteria was not really "good for trailhead... " – robertovg Jul 13 '17 at 10:58
  • I tried the above code and I am getting the following error can you help me out what I am doing wrong This page has an error. You might just need to refresh it. Action failed: c:campingList$controller$clickCreateItem [helper.createItem is not a function] Failing descriptor: {c:campingList$controller$clickCreateItem} – Suresh Dec 11 '17 at 1:43
  • @Suresh, please open a new psot with your relevant code ans specific problem. this way, we will be able to help you. If you were able to resolve, you can answer your own question. Thanks! – glls Dec 21 '17 at 18:45
  • this solution pisses me off. I spent 30 minutes console.logging to find the problem. Turns out trailhead doesn't want you to use helpers! XD – Tyler Zika Jan 24 '18 at 2:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.