• Nash79
  • NEWBIE
  • 25 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 12
    Replies
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!
Hello All
I am trying the exercise "Implementing Global Actions with Visualforce Pages" in the trailhead module module.  
The exercise mentioned "Your users have asked for a quick way to share information about themselves with their clients from their mobile phone. Create a global action in Salesforce1 to display information similar to a user's business card (first and last name, email, phone, and title).
The global action must be labeled 'My Business Card'.
The global action must reference a Visualforce page named 'BusinessCard'.
.................................."

I have created the global action and named with the label correctly as "My Business Card".  However, I am now getting an error as below
"Challenge Not yet complete... here's what's wrong: 
The 'My Business Card' global action wasn't found."

We cannot create an action with the name having spaces as in "My Business Card".   

What am I doing incorrectly.  Please suggest.
Thanks
Bhanu
Hello,

I am using joined report

Is it possibel to take a screenshot of a report (or converting report in to pdf)and get it in apex.

I will later use it to email by scheduler

thank you
  • September 23, 2015
  • Like
  • 1
Hai guys,
The repeater must use the <li> HTML list tag
The repeater must use the apex:outputLink component to link to the respective record detail page
HINT: Record detail pages can be reached by placing a record ID at the root of the URL (e.g. '/<record id>').
how can i achieve it.
my vf page code is
<apex:page standardController="Account" recordSetVar="accounts">
  <apex:form >
  <apex:repeat value="{!accounts}" var="a">
 
  
 <li> <apex:outputLink value="/apex/AccountList?id=00128000005LpU9">
  
  {!Account.Name}
  
  </apex:outputLink>
</li>
  </apex:repeat>
  
  
  </apex:form>
</apex:page>
can any one help me

I want to set a defalut value of a picklist field in VF page.. Please suggest how to acheive?

Hi,

 

  Is there any way to open a visualforce page from a trigger?

Hi,

   I have  the following Apex Page where the form shouldn't submit if there is any validation error.

 

<apex:page showHeader="false" sidebar="false" standardController="Lead"
    extensions="Beneficiary">


    <h1>NGO membership form</h1>

    <apex:form id="myform" styleClass="standard-form"
        enctype="multipart/form-data">

        <apex:outputText value="Organisation" />
        <apex:inputText value="{!Lead.Company}" label="Organisation"
            required="true" id="organisation" />
        <br></br>
        <apex:outputText value="Email" />
        <apex:inputText value="{!Lead.Email__c}" label="Email" required="true"
            id="email" />
        <br></br>
        <apex:outputText value="LastName" />
        <apex:inputText value="{!Lead.LastName}" label="LastName"
            required="true" id="lastname" />
        <br></br>

        <apex:commandButton value="Submit" onclick="validate()" immediate="false"/>
    </apex:form>


    <script>
function validate()
{

    var a = document.getElementById('{!$Component.myform.lastname}').value;
    if(a == null || a.length == 0)
    {
         alert("Last name is a Mandatory Field");
         return null;
    }

}
</script>

</apex:page>

 

If the lastname is blank. I'm getting the validation error. But the form still submits. How to stop the form submission if there is any validation error?

Hello,

 

Is it possible to support localisation for Salesforce sites?

I have not enforced login criteria in the sites. Users can directly access sites through url without logging into the system.

 

Localisation is an urgent requirement of my project.

Please help.

 

Thanks