You need to sign in to do that
Don't have an account?
Ryan Adams 173
Save and Load Records with a Server-Side Controller continued difficulty
Sir,
I am experiencing great difficulty with the following Trailhead module:
Lightning Components Basics, Connect to Salesforce with Server-Side Controllers
located at: https://trailhead.salesforce.com/modules/lex_dev_lc_basics/units/lex_dev_lc_basics_server
*****************************************************************************************************************************
Here is my code:
(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',
'Quantity__c' : 0,
'Price__c' : 0}"/>
<!-- BOXED AREA -->
<fieldset class="slds-box slds-theme--default slds-container--small">
<legend id="newCampItemForm" class="slds-text-heading--small
slds-p-vertical--medium">
Add Camping Item
</legend>
<!-- CREATE NEW CAMPING ITEM FORM -->
<form class="slds-form--stacked">
<div class="slds-form-element slds-is-required">
<div class="slds-form-element__control">
<ui:inputText aura:id="campItemName" 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>
<!-- / CREATE NEW CAMPING ITEM FORM -->
</fieldset>
<div class ="slds-card slds-p-top--meduim">
<header class ="slds-card__header">
<h3 class = "slds-text-heading--small">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>
<!-- i do not think this html is needed any longer
<ol>
<li>Bug Spray</li>
<li>Bear Repellant</li>
<li>Goat Food</li>
</ol>-->
</aura:component>
(campingListController.js)
({
doInit : function(component, event, helper) {
var action = component.get("c.getItems");
action.setCallback(this, function(response){
var state = response.getState();
if (component.isValid() && state === "SUCCESS") {
component.set("v.items", response.getReturnValue());
}
});
$A.enqueueAction(action);
},
CreateCamping : function(component, event, helper){
helper.validateFields (component,component.find("name"));
helper.validateFields (component,component.find("Price"));
helper.validateFields (component,component.find("Quantity"));
if(component.get("v.er") === false)
{
//Here I removed the lines and shifted the code to the helperJs
console.log('Before:'+Items);
helper.CreateCampaign(component,Item);
console.log('After:'+Items);
}
}
})
(campingListHelper.js)
({
validateFields : function (component,field) {
var nameField = field;
console.log('yes:'+nameField);
var expname = nameField.get("v.value");
if ($A.util.isEmpty(expname)){
component.set("v.er",true);
nameField.set("v.errors", [{message:"this field can't be blank."}]);
}
else {
nameField.set("v.errors", null);
}
},
CreateCampaign : function (component,Item){
var action = component.get("c.saveItem");
action.setParams({"CampingItem":Item});
action.setCallback(this,function(response){
var state = response.getState();
if (component.isValid() && state === "SUCCESS") {
console.log('save');
}
});
$A.enqueueAction(action);
//Below lines are shifted from controller Js to helperJs
var Items = component.get("v.items");
var Item = component.get("v.newItem");
Items.push(Item);
component.set("v.items",Items);
component.set("v.newItem",{ 'sobjectType': 'Camping_Item__c',
'Name': '',
'Quantity__c': 0,
'Price__c': 0,
'Packed__c': false });
}
})
*****************************************************************************************************************************
When I do the Check Challenge, I receive the following error:
Challenge Not yet complete... here's what's wrong:
The Apex controller 'CampingListController' does not exist.
The only thing that I can find in the Forum help documentation is that my code has a campingListController.js and a campingListHelper.js, others have a .js file named camperList.js
Please advise.
Ryan
I am experiencing great difficulty with the following Trailhead module:
Lightning Components Basics, Connect to Salesforce with Server-Side Controllers
located at: https://trailhead.salesforce.com/modules/lex_dev_lc_basics/units/lex_dev_lc_basics_server
*****************************************************************************************************************************
Here is my code:
(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',
'Quantity__c' : 0,
'Price__c' : 0}"/>
<!-- BOXED AREA -->
<fieldset class="slds-box slds-theme--default slds-container--small">
<legend id="newCampItemForm" class="slds-text-heading--small
slds-p-vertical--medium">
Add Camping Item
</legend>
<!-- CREATE NEW CAMPING ITEM FORM -->
<form class="slds-form--stacked">
<div class="slds-form-element slds-is-required">
<div class="slds-form-element__control">
<ui:inputText aura:id="campItemName" 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>
<!-- / CREATE NEW CAMPING ITEM FORM -->
</fieldset>
<div class ="slds-card slds-p-top--meduim">
<header class ="slds-card__header">
<h3 class = "slds-text-heading--small">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>
<!-- i do not think this html is needed any longer
<ol>
<li>Bug Spray</li>
<li>Bear Repellant</li>
<li>Goat Food</li>
</ol>-->
</aura:component>
(campingListController.js)
({
doInit : function(component, event, helper) {
var action = component.get("c.getItems");
action.setCallback(this, function(response){
var state = response.getState();
if (component.isValid() && state === "SUCCESS") {
component.set("v.items", response.getReturnValue());
}
});
$A.enqueueAction(action);
},
CreateCamping : function(component, event, helper){
helper.validateFields (component,component.find("name"));
helper.validateFields (component,component.find("Price"));
helper.validateFields (component,component.find("Quantity"));
if(component.get("v.er") === false)
{
//Here I removed the lines and shifted the code to the helperJs
console.log('Before:'+Items);
helper.CreateCampaign(component,Item);
console.log('After:'+Items);
}
}
})
(campingListHelper.js)
({
validateFields : function (component,field) {
var nameField = field;
console.log('yes:'+nameField);
var expname = nameField.get("v.value");
if ($A.util.isEmpty(expname)){
component.set("v.er",true);
nameField.set("v.errors", [{message:"this field can't be blank."}]);
}
else {
nameField.set("v.errors", null);
}
},
CreateCampaign : function (component,Item){
var action = component.get("c.saveItem");
action.setParams({"CampingItem":Item});
action.setCallback(this,function(response){
var state = response.getState();
if (component.isValid() && state === "SUCCESS") {
console.log('save');
}
});
$A.enqueueAction(action);
//Below lines are shifted from controller Js to helperJs
var Items = component.get("v.items");
var Item = component.get("v.newItem");
Items.push(Item);
component.set("v.items",Items);
component.set("v.newItem",{ 'sobjectType': 'Camping_Item__c',
'Name': '',
'Quantity__c': 0,
'Price__c': 0,
'Packed__c': false });
}
})
*****************************************************************************************************************************
When I do the Check Challenge, I receive the following error:
Challenge Not yet complete... here's what's wrong:
The Apex controller 'CampingListController' does not exist.
The only thing that I can find in the Forum help documentation is that my code has a campingListController.js and a campingListHelper.js, others have a .js file named camperList.js
Please advise.
Ryan
APEX Controller campingList.cmp campingListController.js campingListHelper.js
All Answers
Isn't the first line supposed to be like..
?
Try that. If it doesn't work, I will share the code that worked for me.
Challenge Not yet complete... here's what's wrong:
The campingList JavaScript controller isn't calling the helper's 'createItem' function.
CampingListController.apxc
CampingList.cmp
CampingListController.js
CampingListHelper.js
What am I missing?
APEX Controller campingList.cmp campingListController.js campingListHelper.js
Any Help in appriciated.
Correct the spelling of component in line 15 of campingListHelper.
I hope this will work for you.
CampingListController.apxc
CampingListController.js
CampingListHelper.js
The Apex controller CampingListController doesn't have a 'getItems()' or 'saveItem(Camping_Item__c item)' method.