0

i have created an webservices in lightning component.but i got a error.please suggest me for code modification

lightning app:

<aura:application >    
     <LightningConect:vinodtestex />
</aura:application>

component:

<aura:component controller="UIviewPageCtrl2" implements="force:appHostable">
    <aura:registerEvent name="sampleComponentEvent" type="testeventex"/>
    <aura:registerEvent name="sampleComponentEvent1" type="testeventtex"/>
    <aura:registerEvent name="sampleComponentEvent2" type="testeventtex1"/>
    <aura:handler name="sampleComponentEvent" action="{!c.handlerAction}"/>
    <aura:handler name="sampleComponentEvent1" action="{!c.stateAction}"/>
    <aura:handler name="sampleComponentEvent2" action="{!c.districtAction}"/>   
     <div class="form-style">
         Postal Code<br/>
    <ui:inputText class="search-text" aura:id="name" maxlength="10" blur="{!c.myAction}"  value=""/>    

    <ui:inputSelect class="dynamic" aura:id="InputSelectSingle" change="{!c.myState}">
        <aura:iteration items="{!jsonStr}" var="contact">
            <ui:inputSelectOption text="{!contact.Name}"/>
        </aura:iteration>
    </ui:inputSelect>

    <ui:inputSelect class="dynamic" aura:id="InputSelectSinglestate" change="{!c.myDistrict}">
        <aura:iteration items="{!v.state}" var="state">
            <ui:inputSelectOption text="{!state.Name}"/>
        </aura:iteration>
    </ui:inputSelect>
    <ui:inputSelect class="dynamic" aura:id="InputSelectSingleDistrict">
        <aura:iteration items="{!v.district}" var="district">
            <ui:inputSelectOption text="{!district.Name}"/>
        </aura:iteration>
    </ui:inputSelect>
   </div>
</aura:component>

controller:

global class UIviewPageCtrl2{
 @AuraEnabled   
    public static list<string> address{set;get;}
    public String Districts { get; set; } 
    public static list<SelectOption> selectedDistricts { get; set; }

    public String states { get; set; }

    public static list<SelectOption> selectedCountrys { get; set; }
    public static list<SelectOption> selectedStates { get; set; }

    public String country { get; set; }

    public static String postalCode { get; set; }

    public static String baseUrl {get; set;}

    public static String apiKey {get; set;}

    public static String url {get; set;}


public UIviewPageCtrl2(){
address = new list<string>();
}
@AuraEnabled
public static List<Country__c> getDosearch(){

    return null;

}
    @AuraEnabled
public static String getCountry(String searchKey) {

    baseURL = 'http://api-adresse.data.gouv.fr/';

    // Sign up for an API key here: http://www.wunderground.com/weather/api/d/login.html
    //apiKey = 'http://api-adresse.data.gouv.fr/search/?q=8%20bd%20du%20port';
    url = 'http://api-adresse.data.gouv.fr/search/?q=34140';
    HttpRequest req = new HttpRequest();
    Http http = new Http();
    req.setMethod('GET');    
    req.setEndpoint(url);
    req.setHeader('Content-Type', 'application/json');
     try {
        HTTPResponse res = http.send(req);
        System.debug('Result---->'+res.getBody());
        return res.getBody();        

    } catch(Exception ex){
        return '{"error": "' + ex.getMessage() + '"}';
    }

}



    //System.debug('testtttt------>'+searchKey);

    //return [SELECT Id,LightningConect__Zip_del__c,Name FROM LightningConect__Country__c where LightningConect__Zip_del__c in (Select id from LightningConect__Pin_Code__c where name=:searchKey)];
    //return null;

    @AuraEnabled
    public static List<state__c> getState(string stateKey) {

        return[SELECT Id,LightningConect__Country__c,Name FROM LightningConect__State__c where LightningConect__Country__c in (SELECT id from LightningConect__Country__c where name=:stateKey)];
    }
    @AuraEnabled
    public static List<district__c> getMatch(string districtKey) {
        return[SELECT Id,LightningConect__State__c,Name FROM LightningConect__District__c where LightningConect__State__c in (SELECT id from LightningConect__State__c where name=:districtKey)];
    }


@AuraEnabled
public void getDosearchstate(){
        selectedStates = new list<SelectOption>(); 
        system.debug('*********country '+country );
         if(country !='' && country !='--None--'){
                list<state__C > l =[select id, name from state__C where country__c=:country];
                for(state__C pc:l){
                     selectedStates.add(new SelectOption(pc.id,pc.name));  
                }
                country__c s =[select name from country__c where id=:country];
                address.add(s.name);
        }else{
                selectedStates = null; 
                 selectedDistricts = null;
                 address.clear();
        }
}
@AuraEnabled
 public  void getDosearchDistricts() {
         selectedDistricts = new list<SelectOption>(); 
        system.debug('*********country '+states );
         if(states !='' && states !='--None--'){

                list<District__c> l =[select id, name from District__c where state__c=:states ];
                for(District__c pc:l){
                     selectedDistricts.add(new SelectOption(pc.id,pc.name));  
                }
                 state__C s1 =[select name from state__C where id=:states ];
                 address.add(s1.name);
        }else{
                selectedDistricts = null; 
                address.clear();
        }
    }
@AuraEnabled
  public void getDosearchadd(){
 if(Districts!='' && Districts!='--None--'){
District__c s2 =[select name from District__c where id=:Districts];
address.add(s2.name);

}else{
 address.clear();
}
}
}
3
  • First of all, you are going to need a client side controller to access the server-side controller, and you will also need to make your auraenabled methods static, see here salesforce.stackexchange.com/questions/84185/…
    – martin
    Commented Aug 13, 2015 at 7:06
  • please find the client side controller and our requirement is we have the json date inside that api,based on postal code we have to populate the city,street that to be user interface.please modify my code. link is: ({ ap2.salesforce.com/_ui/common/apex/debug/…
    – kiran k
    Commented Aug 13, 2015 at 7:20
  • Maybe you could start by describing the error you see ? Commented Nov 5, 2016 at 12:23

0

You must log in to answer this question.

Browse other questions tagged .