0

I have implemented a trigger and class to get geolocation fields filled in Accounts with the help from this site make geolocation available

Then i wanted to use the findnearby function in addition and added the Apex Class as following

global with sharing class FindNearby {
public FindNearby(ApexPages.StandardController sc){}
@RemoteAction
// Find Accounts nearest a geolocation
global static List getNearby (String lat, String lon) {
// If geolocation isn't set, use Eindhoven (or any other city)
// Put a default location latitue and longitude here, this could be where you are located the most
    // and will only be used as a backup if the browser can not get your location details
    if(lat == null || lon == null || lat.equals('') || lon.equals('')) {
        lat = '51.096214';
        lon = '3.683153';
    }
     // SOQL query to get the nearest accounts
    //you can change km (kilometers) into mi (miles)
    // < 20 means within a radius of 20 km or mi (you can change that)
    //limit 25 shows 25 records (you can adapt that too if you want)
    String queryString =
        'SELECT Id, Name, Location__Longitude__s, Location__Latitude__s, ' +
            'BillingStreet, Phone, BillingCity ' +
        'FROM Account ' +
        'WHERE DISTANCE(Location__c, GEOLOCATION('+lat+','+lon+'), \'km\') < 20 ' +
        'ORDER BY DISTANCE(Location__c, GEOLOCATION('+lat+','+lon+'), \'km\') ' +
        'LIMIT 25';
     // Run and return the query results
    return(database.Query(queryString));
}}

but then, I got the Error, that in line 5 an left angle bracket is missing Error Code in detail: "expecting a left angle bracket, found 'getnearby' when i added a left angle bracket, it tells me "unexpected token: '('

Do you have any clue, what am i missing here? I originally copied the class text from the website without any change to it.

Thanks a lot in advance for your support.

Ralf

  • 2
    You are returning a List of .... Accounts, the syntax is like so: List<Account> – Mihai Neagoe Oct 2 '15 at 8:51
  • Hi Mihai, but this code is exactly like in the thread from the website, where other users don´t have problems with. Can this maybe caused by Salesforce updates, as this thread is from older 2014 – Ralf Wittenberger Oct 2 '15 at 8:57
  • Maybe it's a typo on the website ? – Mihai Neagoe Oct 2 '15 at 8:58
0

global static List getNearby (String lat, String lon) { you need to change this line into

global static List<sObject> getNearby (String lat, String lon) {

try this and update if it is works for you.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.