function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
DomJHDomJH 

Unable to make simple class envokable - find custom location record based on coordinate input

Hello,

I've got a simple class containing a SOQL query that finds the nearest custom location record based on input of 2 coordinates:
 
public with sharing class NearestLocation {
 	
    @InvocableMethod(label='Get Nearest location' description='From given coordinates the nearest location is returned')
    public static List<custom__Location__c> getLocation(List<FlowInput> requests)
    {
  
        List<custom__Location__c> locList =
        [SELECT  id, Name
        FROM custom__Location__c  WHERE RecordType.Name = 'Synced' AND 
        DISTANCE(custom__GeoLocation__c, GEOLOCATION(:requests[0].coordlat, :requests[0].coordlng), 'km')<1
        ORDER BY DISTANCE(custom__GeoLocation__c, GEOLOCATION(:requests[0].coordlat, :requests[0].coordlng), 'km')
                         LIMIT 1];
    
      for(custom__Location__c lc : locList)
      {
          system.debug('~~!~~!~~' + lc.id);
          system.debug('~~!~~!~~' + lc.name);
      }
            return locList;
    }
    
        public class FlowInput 
        {
        	@InvocableVariable(required=true)
    		public decimal coordlat;
        	@InvocableVariable(required=true)
			public decimal coordlng;
        }
  }
The above code works as expected when run from Execute Anon:
list <NearestLocation.FlowInput> fi = new list<NearestLocation.FlowInput>();

NearestLocation.FlowInput x1 = new NearestLocation.FlowInput();

x1.coordlat = 53.243213;
x1.coordlng = -1.475886;

fi.add(x1);

NearestLocation.getLocation(fi);

However, I'm tring to get it to be 'envoked' from within a lightning flow, but it fails with a generic 'flow has vaildation errors'​ message.

flow element - apex action

Execution log showing generic flow validation error
I'm obviously missing something and was wondering if anyone could offer some guidance/thoughts?

many thanks, Dom
 
Best Answer chosen by DomJH
DomJHDomJH
RESOLVED. 

Nothing inheritently wrong with the code....problems were due to unrelated formula in the lightning flow!  Hmmm...note to self...start with a blank canvas!