• Siddardha Jonnalagadda 4
  • NEWBIE
  • 10 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 0
    Replies
Hi,
I am trying to execute the following code but its trowing me a errror please help me out.

InTheArea Apex class

public class InTheArea {
    @AuraEnabled
        public static String getLocal (String searchTerm, Decimal lat, Decimal lon) {
        String url = 'https://th-yelp-locator.herokuapp.com/search?address=' + lat +','+ lon + '&term=' + EncodingUtil.urlEncode(searchTerm, 'UTF-8');
        HttpRequest req = new HttpRequest();
        Http http = new Http();
        req.setMethod('GET');    
        req.setEndpoint(url);
        HTTPResponse res = http.send(req);
        return res.getBody();   
    }
}

InTheArea.cmp
<aura:component controller="InTheArea" implements="force:appHostable, flexipage:availableForAllPageTypes, flexipage:availableForRecordHome, force:hasRecordId" access="global" >
<aura:attribute name="defaultSearch" type="String" default="Restaurants" />
<aura:attribute name="location" type="Object" default='{"coords":{"latitude":37.7938462, "longitude":-122.3970253}}' />
<aura:attribute name="restaurantList" type="Object" />
<aura:handler name="init" value="{!this}" action="{!c.doInit}" />
<div class="slds">
  <div class="slds-box" aura:id="main">
    <div aura:id="panelList">
      <header>
        <h2 class="slds-text-heading--small slds-m-bottom--small">In the Area</h2>
        <div class="slds-form-element">
          <label class="slds-form-element__label slds-assistive-text" for="searchBox">Search</label>
          <div class="slds-form-element__control">
              <ui:inputText aura:id="searchTerm" label="" class="field" placeholder="Search for..." change="{!c.updateSearch}" />
          </div>
        </div>
      </header>
      <div aura:id="scrollableArea">
        <ul class="slds-list--vertical slds-has-dividers--top-space">
          <li class="slds-list__item">
              <h3 class="slds-text-heading--small slds-m-bottom--x-small">Item 1</h3>
          </li>
          <li class="slds-list__item">
              <h3 class="slds-text-heading--small slds-m-bottom--x-small">Item 2</h3>
          </li>
          <li class="slds-list__item">
              <h3 class="slds-text-heading--small slds-m-bottom--x-small">Item 3</h3>
          </li>
        </ul>
      </div>
    </div>
  </div>
</div>
</aura:component>

InTheAreaController:

({
    doInit : function(component, event, helper) {
    helper.getLocalList(component);

}
})

InTheAreaHelper.js
({
    getLocalList: function(component) {
        var searchTerm = component.get("v.defaultSearch");
        var location = component.get("v.location");
        var action = component.get("c.getLocal");
        location = JSON.parse(location);
        action.setParams({
            "searchTerm": searchTerm,
            "lat": location.coords.latitude,
            "lon": location.coords.longitude
        });
        action.setCallback(this, function(response) {
            this.doLayout(response, component);
        });
        $A.enqueueAction(action);
    },
    // add doLayout function
    doLayout: function(response, component) {
        var data = JSON.parse(response.getReturnValue());
        component.set("v.restaurantList", data.bizArray);
        console.log("The Data: ", data);
    }    
})

ERROR:
Uncaught Error in $A.getCallback() [Cannot read property 'bizArray' of null]
Callback failed: apex://InTheArea/ACTION$getLocal
throws at https://cunning-moose-491973-dev-ed.lightning.force.com/auraFW/javascript/YKnqxnHX5EzqqKoVZYsoZQ/aura_prod.js:2:15
Object.doLayout()@components/c/InTheArea.js:32:47
Object.<anonymous>()@components/c/InTheArea.js:26:18
 
Apex Code:
public class savecontroller {
private final Account acct;
    public savecontroller(ApexPages.StandardController controller) {
        this.acct = (Account)controller.getRecord();
    }
    public void autosave()
    {
        update acct;
    }  
}

Visual Force Page code:
<apex:page standardController="Account" extensions="savecontroller">
<apex:form >
<apex:pageblock >
<!-- The action function which calles the Apex function 'autosave' -->
<apex:actionFunction name="autosave" action="{!autosave}" rerender="out" status="savestatus"/>

<!-- A status denotion of the update -->
<apex:actionStatus id="savestatus">
          <apex:facet name="start"> Auto Saving....</apex:facet> 
</apex:actionStatus>

<apex:pageblocksection columns="2">
      <apex:inputfield value="{!Account.Name}"/>
      <apex:inputfield value="{!Account.BillingCity}"/>
      <apex:inputfield value="{!Account.BillingCountry}"/>
      <apex:inputfield value="{!Account.BillingState}"/>
</apex:pageblocksection>      
</apex:pageblock>

<!-- A javascript recursive function which calls itself every 10 seconds, the setTimeout method calls the apex function 'autosave' defined in the <apex:actionfunction> tag above -->
<script>
          window.setTimeout(recursivecall,10000);
          function recursivecall()
          {
              window.setTimeout(recursivecall,10000);
              autosave();
          }    
</script>
                
</apex:form>      
</apex:page>

Error:

Update failed. First exception on row 0; first error: MISSING_ARGUMENT, Id not specified in an update call: []
Error is in expression '{!autosave}' in page sample: Class.savecontroller.autosave: line 8, column 1