• Shashwat Nandan
  • NEWBIE
  • 0 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    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