• Chirag Gulati
  • NEWBIE
  • 5 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 3
    Replies
Hey folks,

I'm trying to achieve a very simple thing, creating a new record in SF from a Lightning Component. But facing a weird situation/issue. While submitting the form it's going in an infinite loop. I doubt there is a silly mistake which I'm unable to identify hence need another pair of eyes. Here is the code snippet. 
<aura:component implements="force:appHostable">
  <ltng:require styles="{!$Resource.SLDSv1 + 
       '/assets/styles/salesforce-lightning-design-system-ltng.css'}"/>
  <aura:attribute name="expenses" type="chirag__Expense__c[]"/>
  <aura:attribute name="newExpense" type="chirag__Expense__c"
         default="{ 'sobjectType': 'chirag__Expense__c',
                         'Name': '',
                         'chirag__Amount__c': 0,
                         'chirag__Client__c': '', 
                         'chirag__Date__c': '',
                         'chirag__Reimbursed__c': false
                       }"/>
  
  <!-- Attributes for Expense Counters -->
  <aura:attribute name="total" type="Double" default="0.00" />
  <aura:attribute name="exp" type="Double" default="0" />

  <!-- Input Form using components -->
  <div class="container">
    <form class="slds-form--stacked">
      <div class="slds-form-element slds-is-required">
        <div class="slds-form-element__control">

       <!-- If you registered a namespace,
            the attributes include your namespace.
            For example, value="{!v.newExpense.myNamespace__Amount__c}" -->

          <ui:inputText aura:id="expname" label="Expense Name"
                        class="slds-input"
                        labelClass="slds-form-element__label"
                        value="{!v.newExpense.Name}"
                        required="true"/>
         </div>
       </div>
       <div class="slds-form-element slds-is-required">
         <div class="slds-form-element__control">
           <ui:inputNumber aura:id="amount" label="Amount"
                           class="slds-input"
                           labelClass="slds-form-element__label"
                           value="{!v.newExpense.Amount__c}"
                           placeholder="20.80" required="true"/>
          </div>
        </div>
        <div class="slds-form-element">
          <div class="slds-form-element__control">
            <ui:inputText aura:id="client" label="Client"
                          class="slds-input"
                          labelClass="slds-form-element__label"
                          value="{!v.newExpense.Client__c}"
                          placeholder="ABC Co."/>
           </div>
         </div>
         <div class="slds-form-element">
           <div class="slds-form-element__control">
             <ui:inputDateTime aura:id="expdate" label="Expense Date"
                               class="slds-input"
                               labelClass="slds-form-element__label"
                               value="{!v.newExpense.Date__c}"
                               displayDatePicker="true"/>
            </div>
          </div>
          <div class="slds-form-element">
            <ui:inputCheckbox aura:id="reimbursed" label="Reimbursed?"
                              class="slds-checkbox"
                              labelClass="slds-form-element__label"
                              value="{!v.newExpense.Reimbursed__c}"/>
            <ui:button label="Submit" 
                       class="slds-button slds-button--neutral"
                       labelClass="label"
                       press="{!c.createExpense}"/>
           </div>
    </form>
  </div><!-- ./container-->

  <!-- Expense Counters -->
  <div class="container slds-p-top--medium">
        <div class="row">
            <div class="slds-tile ">
                <!-- Make the counter red if total amount is more than 100 -->
                <div class="{!v.total >= 100 
                     ? 'slds-notify slds-notify--toast slds-theme--error slds-theme--alert-texture' 
                     : 'slds-notify slds-notify--toast slds-theme--alert-texture'}">
                    <p class="slds-tile__title slds-truncate">Total Expenses</p>
                    $<ui:outputNumber class="slds-truncate" value="{!v.total}" format=".00"/>
                </div>
            </div>
            <div class="slds-tile ">
                <div class="slds-notify slds-notify--toast slds-theme--alert-texture">
                      <p class="slds-tile__title slds-truncate">No. of Expenses</p>
                      <ui:outputNumber class="slds-truncate" value="{!v.exp}"/>
                  </div>
            </div>
        </div>
    </div>
          <!-- Display expense records -->
          <div class="container slds-p-top--medium">
              <div id="list" class="row">
                 <aura:iteration items="{!v.expenses}" var="expense">

                     <!-- If you’re using a namespace, 
                          use the format 
                          {!expense.myNamespace__myField__c} instead. -->

                     <p>{!expense.Name}, {!expense.Client__c}, 
                        {!expense.Amount__c}, {!expense.Date__c}, 
                        {!expense.Reimbursed__c}</p>                     
                </aura:iteration>
              </div>
          </div> 
</aura:component>
 
({
	doInit : function(component, event, helper) {
		var action = component.get('c.getExpenses');
        action.setCallback(this, function(response) {
           var state = response.getState();
            if (component.isValid() && state == "SUCCESS") {
                component.set("v.expenses", response.getReturnValue());
            }
            else {
                console.log("Failed with state: " + state);
            }
        });	 
        $A.enqueueAction(action);
	},
    
    createExpense : function(component, event, helper) {
		//update expense counters
		console.log('createExpense');
        alert('createExpense');
		var expense = component.get("v.newExpense");
        debugger;
		helper.createItem(component, expense);		 
	}
})
 
({
	helperMethod : function() {
		
	},
    
    createItem: function(component, expense) {
		console.log('createItem');
        var action = component.get("c.createExpense");
        action.setParams({
            "expense": expense
        });
        action.setCallback(this, function(response){
        var state = response.getState();
        if (component.isValid() && state == "SUCCESS") {
            console.log('state+++' + state);
            var campings = component.get("v.expenses");
            //campings.push(response.getReturnValue());
            component.set("v.expenses", response.getReturnValue());
        }
    	});
    	
        $A.enqueueAction(action);
	}
})

I suspect there is something wrong with helper method, it is calling back the controller method again and again.

Thanks in advance.
I am not able to complete the che challenge "Set Up and Manage Shield Platform Encryption". Everytime it shows "The Case Description field does not appear to be encrypted. Make sure you have records with data in this field." Although I encrypted the Case description filed. Anyone have any idea how to get rid of it. Please help me. I am stucked in this step for two days.
I cannot for the life of me, figure out what could be wrong with my campingList component markup for the "Create a Simple Camping List Lightning Component" challenge.  This is the markup for campingList.cmp:

<aura:component>
     <ul>
        <li>Bug Spray</li>
        <li>Bear Repellant</li>
        <li>Goat Food</li>
    </ul>
 </aura:component>

Please help me figure out why I am getting the error.  Thank you, Susan

 
provided challange is: Create a Message of The Day component that displays different text based on an attribute...
https://developer.salesforce.com/trailhead/lex_dev/lightning_components/lightning_components_expressions

i completed this challenge but traihead is not accepting it.. it is giving me error. i.e. : 
Challenge not yet complete... here's what's wrong: 
The component is not evaluating the value of the 'DayOfTheWeek' attribute to determine what to display


but when i execute my component it gives me desired output....