Lightning Components Basics: Connect to Salesforce with Server Side Controllers
Campaign List Component Code
<aura:component controller="CampingListController"
implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,force:lightningQuickAction" access="global" >
<aura:handler name="init" action="{!c.doInit}" value="{!this}"/>
<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,
'Packed__c': false }"/>
<!--<ol>
<li>Bug Spray</li>
<li>Bear Repellant</li>
<li>Goat Food</li>
</ol> -->
<!-- PAGE HEADER -->
<c:campingHeader />
<lightning:layout >
<lightning:layoutItem padding="around-small" size="6">
<div aria-labelledby="newcampaignform">
<fieldset class="slds-box slds-theme--default slds-container--small">
<legend id="newcampaignform" class="slds-text-heading--small slds-p-vertical--medium">
Add Campaign List
</legend>
<form class="slds-form--stacked">
<lightning:input aura:id="campaignform" label="Campaign Item Name"
name="campaignitemname"
value="{!v.newItem.Name}"
required="true"/>
<lightning:input type="number" aura:id="expenseform" label="Quantity"
name="campaignitemprice"
min="1"
formatter="number"
step="0.1"
value="{!v.newItem.Quantity__c}"
messageWhenRangeUnderflow="Enter quantity that's at least 1."/>
<lightning:input type="number" aura:id="expenseform" label="Price"
name="campaignitemprice"
min="0.1"
formatter="currency"
step="0.01"
value="{!v.newItem.Price__c}"
messageWhenRangeUnderflow="Enter an amount that's at least $0.10."/>
<lightning:input type="checkbox" aura:id="expenseform" label="Packed?"
name="expreimbursed"
checked="{!v.newItem.Packed__c}"/>
<lightning:button label="Create Camping" class="slds-m-top--medium"
variant="brand" onclick="{!c.clickCreateItem}"/>
</form>
</fieldset>
</div>
</lightning:layoutItem>
</lightning:layout>
<c:campingHeader />
<div class="slds-card slds-p-top--medium">
<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="items">
<c:campingListItem item="{!item}"/>
</aura:iteration>
</div>
</section>
</div>
</aura:component>
CampaignListController Code
({
// Load expenses from Salesforce
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 (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) {
var validCamping = component.find('campingform').reduce(function (validSoFar, inputCmp) {
// Displays error messages for invalid fields
inputCmp.showHelpMessageIfInvalid();
return validSoFar && inputCmp.get('v.validity').valid;
}, true);
if(validCamping){
var addItm = event.getParam("item");
helper.createItem(component, addItm);
var newCampingItem = component.get("v.newItem");
var campings = component.get("v.items");
var item = JSON.parse(JSON.stringify(newCampingItem));
campings.push(item);
component.set("v.items",campings);
component.set("v.newItem",{ 'sobjectType': 'Camping_Item__c','Name': '','Quantity__c': 0,
'Price__c': 0,'Packed__c': false });
}
}
})
Campaign List Helper Code
({
createItem : function(component, campaign) {
var action = component.get("c.saveItem");
action.setParams({
"item": campaign
});
action.setCallback(this, function(response){
var state = response.getState();
if (state === "SUCCESS") {
var expenses = component.get("v.items");
expenses.push(response.getReturnValue());
component.set("v.items", expenses);
}
});
$A.enqueueAction(action);
},
})
Challenge Not yet complete... here's what's wrong:
ReplyDeleteThe Apex controller CampingListController doesn't have a 'getItems()' or 'saveItem(Camping_Item__c item)' method.
This is one awesome blog article. Much thanks again salesforce Online Training Bangalore
ReplyDeleteNice blog!! thank you.
ReplyDeleteHere is the missed class code:
public class CampingListController {
@auraenabled
public static List getItems (){
List CI = [select id, name,price__c,Quantity__c,Packed__c from Camping_Item__c ];
return CI;
}
@auraenabled
public static Camping_Item__c saveItem (Camping_Item__c CampingItem){
insert campingItem;
return campingItem;
}
}
This comment has been removed by the author.
DeleteThis comment has been removed by the author.
DeleteYou're missing the List type in your getItems() method. Make sure to use List < Camping_Item__c > in both places in that method instead of just declaring List by itself.
DeleteAfter trying to comment several times, I realized the site is automatically removing what's in between the < and > unless I put spaces like above. Hope that helps anyone reading this.
Thanks for pasting the code! It helped me troubleshoot my challenge!
ReplyDeleteGreat Post. The information provided is of great use as I got to learn new things. Keep Blogging.Dell Boomi Training in Bangalore
ReplyDeleteHi All,
ReplyDeleteI am still gettingThe Apex controller CampingListController doesn't have a 'getItems()' or 'saveItem(Camping_Item__c item)' method. error.
This comment has been removed by the author.
ReplyDeletepublic class CampingListController {
ReplyDelete@auraenabled
public static List getItems (){
List CI = [select id, name,price__c,Quantity__c,Packed__c from Camping_Item__c ];
return CI;
}
@auraenabled
public static List saveItem (Camping_Item__c CampingItem){
insert campingItem;
return campingItem;
}
}
Just found your post by searching on the Google, I am Impressed and Learned Lot of new thing from your post.
ReplyDeleteDell Boomi training in bangalore
Thanks for sharing this in here. You are running a great blog, keep up this good work.
ReplyDeleteDell Bhoomi online training
Dell Bhoomi online training Hyderabad
java online courses
ReplyDeletesalesforce online courses
hadoop online courses
Data Science online courses
linux online courses
etl testing online courses
web methods online courses
Dell Bhoomi online course
ReplyDeleteDell Bhoomi online training
The dachshund was bred in Germany hundreds of years ago to hunt badgers. https://www.poodlespring.com/ "Dach" means badger and "hund" means dog. The three varieties of dachshund, smooth-, Dachshund puppies for sale wire-,and long-coated, originated at different times. The smooth was the first and arose from a mixture of a miniature French pointer and a pinscher. The breed also comes in two sizes: standard and miniature, with the standard the original size.
ReplyDeleteThe dachshund has short, strong legs that enable the dog to dig out prey and go inside burrows. Larger versions of the breed were used to chase deer or fox. Smaller dachshunds Dachshund puppy for sale were bred for hunting hares and ferrets.
The breed is still used for hunting, primarily in Europe, nine in dachshunds puppies for sale ches in height.All three types are known
The dachshund's coat may be shades of red, black, chocolate, white or gray. Some have tan markings or are spotted or dappled. Dachshunds live about 12 to 15 years. toy poodle for sale espite their size, dachshunds are known for their courageous nature and will take on animals much larger than themselves. Some may be aggressive toward strangers and other dogs.
As family dogs, dachshunds are loyal companions and good watchdogs. They are good with children if treated well. They can be slightly difficult to train.
Some dachshund fanciers say there are personality differences among the different varieties of the breed. For instance, the long-coat dachshund is reportedly calmer teacup poodles for sale than the smooth-coat variety,
seo fiyatları
ReplyDeletesaç ekimi
dedektör
instagram takipçi satın al
ankara evden eve nakliyat
fantezi iç giyim
sosyal medya yönetimi
mobil ödeme bozdurma
kripto para nasıl alınır
bitcoin nasıl alınır
ReplyDeletetiktok jeton hilesi
youtube abone satın al
gate io güvenilir mi
referans kimliği nedir
tiktok takipçi satın al
bitcoin nasıl alınır
mobil ödeme bozdurma
mobil ödeme bozdurma
mmorpg oyunlar
ReplyDeleteinstagram takipçi satın al
tiktok jeton hilesi
tiktok jeton hilesi
antalya saç ekimi
referans kimliği nedir
İNSTAGRAM TAKİPÇİ SATIN AL
Mt2 Pvp Serverlar
INSTAGRAM TAKİPCİ
perde modelleri
ReplyDeletesms onay
MOBİL ODEME BOZDURMA
nft nasil alınır
ANKARA EVDEN EVE NAKLİYAT
trafik sigortası
DEDEKTÖR
Site kurma
aşk kitapları
Smm Panel
ReplyDeleteSMM PANEL
iş ilanları
İnstagram takipçi satın al
hirdavatciburada.com
beyazesyateknikservisi.com.tr
servis
Tiktok hile
Good content. You write beautiful things.
ReplyDeletemrbahis
vbet
hacklink
vbet
sportsbet
korsan taksi
taksi
sportsbet
hacklink