- Stéphane Bernhardt SalesForce
- NEWBIE
- 10 Points
- Member since 2015
-
ChatterFeed
-
0Best Answers
-
0Likes Received
-
0Likes Given
-
1Questions
-
1Replies
Trailhead - Connect to Salesforce with Server-Side Controllers - Internal error
Hi,
I'm currently working on the "Connect to Salesforce with Server-Side Controllers" module and I'm facing an error.
The error is:
Error: An internal server error has occurred
Error ID: 615929029-122427 (-1189130377)
I already:
I did not have any issue on the previous unit, with expenses.
Please find my code below. Do you have an idea because I'm going crazy :)
Camping.cmp:
CampingItem.cmp:
campingListHelper.js:
I'm currently working on the "Connect to Salesforce with Server-Side Controllers" module and I'm facing an error.
The error is:
Error: An internal server error has occurred
Error ID: 615929029-122427 (-1189130377)
I already:
- Re-wrote the code from zero
- Checked other posts on this forum
- Checked fields security
- Tried to remove the "with sharing" from the Apex controller
I did not have any issue on the previous unit, with expenses.
Please find my code below. Do you have an idea because I'm going crazy :)
Camping.cmp:
<aura:component> <aura:attribute name="items" type="Camping_Item__c[]"/> <!-- PAGE HEADER --> <div class="slds-page-header" role="banner"> <div class="slds-grid"> <div class="slds-col"> <p class="slds-text-heading--label">Camping items</p> <h1 class="slds-text-heading--medium">Items</h1> </div> </div> </div> <!-- / PAGE HEADER --> <c:campingList items="{!v.items}"/> </aura:component>campingList.cmp:
<aura:component controller="CampingListController"> <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': 'Expense__c', 'Name': '', 'Price__c': 0, 'Quantity__c': '', 'Packed__c': false }"/> <!-- NEW EXPENSE FORM --> <div class="slds-col slds-col--padded slds-p-top--large"> <div aria-labelledby="newitemform"> <!-- BOXED AREA --> <fieldset class="slds-box slds-theme--default slds-container--small"> <legend id="newItemform" class="slds-text-heading--small slds-p-vertical--medium"> Add Item </legend> <!-- CREATE NEW EXPENSE FORM --> <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="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="itemprice" label="Price" class="slds-input" labelClass="slds-form-element__label" value="{!v.newItem.Price__c}" required="true"/> </div> </div> <div class="slds-form-element"> <div class="slds-form-element__control"> <ui:inputNumber aura:id="itemquantity" label="Quantity" class="slds-input" labelClass="slds-form-element__label" value="{!v.newItem.Quantity__c}"/> </div> </div> <div class="slds-form-element"> <ui:inputCheckbox aura:id="itempacked" 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 Item" class="slds-button slds-button--brand" press="{!c.clickCreateItem}"/> </div> </form> <!-- / CREATE NEW EXPENSE FORM --> </fieldset> <!-- / BOXED AREA --> </div> <!-- / CREATE NEW EXPENSE --> </div> <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:CampingItem item="{!item}"/> </aura:iteration> </div> </section> </div> </aura:component>
CampingItem.cmp:
<aura:component > <aura:attribute name="item" type="Camping_Item__c"/> <p>Name: <ui:outputText value="{!v.item.Name}"/> </p> <p>Price: <ui:outputNumber value="{!v.item.Price__c}"/> </p> <p>Quantity: <ui:outputNumber value="{!v.item.Quantity__c}"/> </p> <p>Packed?: <ui:outputCheckbox value="{!v.item.Packed__c}"/> </p> </aura:component>CampingListController.apxc:
public with sharing class CampingListController { @AuraEnabled public static List<Camping_Item__c> getItems() { // Perform isAccessible() checking first, then return [SELECT Name, Price__c, Quantity__c, Packed__c FROM Camping_Item__c]; } @AuraEnabled public static Camping_Item__c saveItem(Camping_Item__c newItem) { // Perform isUpdatable() checking first, then upsert newItem; return newItem; } }campingListController.js:
({ // Load items 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 (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)){ // Create the new item var newItem = component.get("v.newItem"); helper.createItem(component, newItem); } } })
campingListHelper.js:
({ validateItemForm: function(component) { // Simplistic error checking var validItem = true; /* // Name must not be blank var nameField = component.find("expname"); var expname = nameField.get("v.value"); if ($A.util.isEmpty(expname)){ validExpense = 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 amtField = component.find("amount"); var amt = amtField.get("v.value"); if ($A.util.isEmpty(amt) || isNaN(amt) || (amt <= 0.0)){ validExpense = false; amtField.set("v.errors", [{message:"Enter an expense amount."}]); } else { // If the amount looks good, unset any errors... amtField.set("v.errors", null); } */ return(validItem); }, createItem: function(component, newItem) { var action = component.get("c.saveItem"); alert(JSON.stringify(newItem)); action.setParams({"newItem": newItem}); action.setCallback(this, function(response){ var state = response.getState(); if (state === "ERROR") { var errors = response.getError(); if (errors && errors[0]) { console.log(errors[0]); } else { console.log("Unknown error"); } } else if (component.isValid() && state === "SUCCESS") { var items = component.get("v.items"); items.push(response.getReturnValue()); component.set("v.items", items); } }); $A.enqueueAction(action); } })Thanks !
- Stéphane Bernhardt SalesForce
- November 01, 2016
- Like
- 0
Trailhead - Connect to Salesforce with Server-Side Controllers - Internal error
Hi,
I'm currently working on the "Connect to Salesforce with Server-Side Controllers" module and I'm facing an error.
The error is:
Error: An internal server error has occurred
Error ID: 615929029-122427 (-1189130377)
I already:
I did not have any issue on the previous unit, with expenses.
Please find my code below. Do you have an idea because I'm going crazy :)
Camping.cmp:
CampingItem.cmp:
campingListHelper.js:
I'm currently working on the "Connect to Salesforce with Server-Side Controllers" module and I'm facing an error.
The error is:
Error: An internal server error has occurred
Error ID: 615929029-122427 (-1189130377)
I already:
- Re-wrote the code from zero
- Checked other posts on this forum
- Checked fields security
- Tried to remove the "with sharing" from the Apex controller
I did not have any issue on the previous unit, with expenses.
Please find my code below. Do you have an idea because I'm going crazy :)
Camping.cmp:
<aura:component> <aura:attribute name="items" type="Camping_Item__c[]"/> <!-- PAGE HEADER --> <div class="slds-page-header" role="banner"> <div class="slds-grid"> <div class="slds-col"> <p class="slds-text-heading--label">Camping items</p> <h1 class="slds-text-heading--medium">Items</h1> </div> </div> </div> <!-- / PAGE HEADER --> <c:campingList items="{!v.items}"/> </aura:component>campingList.cmp:
<aura:component controller="CampingListController"> <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': 'Expense__c', 'Name': '', 'Price__c': 0, 'Quantity__c': '', 'Packed__c': false }"/> <!-- NEW EXPENSE FORM --> <div class="slds-col slds-col--padded slds-p-top--large"> <div aria-labelledby="newitemform"> <!-- BOXED AREA --> <fieldset class="slds-box slds-theme--default slds-container--small"> <legend id="newItemform" class="slds-text-heading--small slds-p-vertical--medium"> Add Item </legend> <!-- CREATE NEW EXPENSE FORM --> <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="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="itemprice" label="Price" class="slds-input" labelClass="slds-form-element__label" value="{!v.newItem.Price__c}" required="true"/> </div> </div> <div class="slds-form-element"> <div class="slds-form-element__control"> <ui:inputNumber aura:id="itemquantity" label="Quantity" class="slds-input" labelClass="slds-form-element__label" value="{!v.newItem.Quantity__c}"/> </div> </div> <div class="slds-form-element"> <ui:inputCheckbox aura:id="itempacked" 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 Item" class="slds-button slds-button--brand" press="{!c.clickCreateItem}"/> </div> </form> <!-- / CREATE NEW EXPENSE FORM --> </fieldset> <!-- / BOXED AREA --> </div> <!-- / CREATE NEW EXPENSE --> </div> <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:CampingItem item="{!item}"/> </aura:iteration> </div> </section> </div> </aura:component>
CampingItem.cmp:
<aura:component > <aura:attribute name="item" type="Camping_Item__c"/> <p>Name: <ui:outputText value="{!v.item.Name}"/> </p> <p>Price: <ui:outputNumber value="{!v.item.Price__c}"/> </p> <p>Quantity: <ui:outputNumber value="{!v.item.Quantity__c}"/> </p> <p>Packed?: <ui:outputCheckbox value="{!v.item.Packed__c}"/> </p> </aura:component>CampingListController.apxc:
public with sharing class CampingListController { @AuraEnabled public static List<Camping_Item__c> getItems() { // Perform isAccessible() checking first, then return [SELECT Name, Price__c, Quantity__c, Packed__c FROM Camping_Item__c]; } @AuraEnabled public static Camping_Item__c saveItem(Camping_Item__c newItem) { // Perform isUpdatable() checking first, then upsert newItem; return newItem; } }campingListController.js:
({ // Load items 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 (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)){ // Create the new item var newItem = component.get("v.newItem"); helper.createItem(component, newItem); } } })
campingListHelper.js:
({ validateItemForm: function(component) { // Simplistic error checking var validItem = true; /* // Name must not be blank var nameField = component.find("expname"); var expname = nameField.get("v.value"); if ($A.util.isEmpty(expname)){ validExpense = 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 amtField = component.find("amount"); var amt = amtField.get("v.value"); if ($A.util.isEmpty(amt) || isNaN(amt) || (amt <= 0.0)){ validExpense = false; amtField.set("v.errors", [{message:"Enter an expense amount."}]); } else { // If the amount looks good, unset any errors... amtField.set("v.errors", null); } */ return(validItem); }, createItem: function(component, newItem) { var action = component.get("c.saveItem"); alert(JSON.stringify(newItem)); action.setParams({"newItem": newItem}); action.setCallback(this, function(response){ var state = response.getState(); if (state === "ERROR") { var errors = response.getError(); if (errors && errors[0]) { console.log(errors[0]); } else { console.log("Unknown error"); } } else if (component.isValid() && state === "SUCCESS") { var items = component.get("v.items"); items.push(response.getReturnValue()); component.set("v.items", items); } }); $A.enqueueAction(action); } })Thanks !
- Stéphane Bernhardt SalesForce
- November 01, 2016
- Like
- 0