+ Start a Discussion
iyappan kandasamy 4iyappan kandasamy 4 

Unexpected token 'Map'. at line 32 column 12

Unexpected token 'Map'. at line 32 column 12
===================================

public with sharing class AccountWeatherController {

    public String city {get;set;}
    public String temp {get;set;}
    public String pressure {get;set;}
    public String humidity {get;set;}
    public String temp_min {get;set;}
    public String temp_max {get;set;}

    public AccountWeatherController(ApexPages.StandardController stdController) {
        Account account = (Account)stdController.getRecord();
        account = [SELECT Id, ShippingCity FROM Account WHERE Id =:account.Id];
        
        String accountCity = account.ShippingCity;
        String apiKey = 'XxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxX';

        String requestEndpoint = 'http://api.openweathermap.org/data/2.5/weather';
        requestEndpoint += '?q=' + accountCity;
        requestEndpoint += '&units=metric';
        requestEndpoint += '&APPID=' + apiKey;
        
        Http http = new Http();
        HttpRequest request = new HttpRequest();
        request.setEndpoint(requestEndpoint);
        request.setMethod('GET');
        HttpResponse response = http.send(request);

        // If the request is successful, parse the JSON response.
        if (response.getStatusCode() == 200) {

           // Deserialize the JSON string into collections of primitive data types.
           Map results = (Map) JSON.deserializeUntyped(response.getBody());
           city = String.valueOf(results.get('name'));
           
           Map mainResults = (Map)(results.get('main'));
           temp = String.valueOf(mainResults.get('temp'));
           pressure = String.valueOf(mainResults.get('pressure'));
            humidity = String.valueOf(mainResults.get('humidity')); 
            temp_min = String.valueOf(mainResults.get('temp_min')); 
            temp_max = String.valueOf(mainResults.get('temp_max'));
        
        } else {
            ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR,'There was an error retrieving the weather information.');
           ApexPages.addMessage(myMsg);
        }
    

    }
}

next to the comments (// Deserialize the JSON string into collections of primitive data types.)

the lines having Map are throwing the above error as "Unexpected token 'Map'. at line 32 column 12"

It would be great to solve the above issue....thanks a lot
          

Steven NsubugaSteven Nsubuga
Salesforce does not allow an untyped Map collection. The Map must have a type, and have a key and value pair defined. See below
Map<String, Opportunity> dataMap
We do not know what your JSON response looks like. Take a look at these examples and fix your code accordingly. See examples below
iyappan kandasamy 4iyappan kandasamy 4
Thanks for your response..will implement it.. Sent from Yahoo Mail on Android