• DomJH
  • NEWBIE
  • 0 Points
  • Member since 2014
  • D J Horton Consulting Ltd


  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 2
    Replies
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
 
  • January 30, 2020
  • Like
  • 0
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
 
  • January 30, 2020
  • Like
  • 0
We are looking for help to migrate to Salesforce with 10 Users.
We still have our data in our current crm vtiger
We need also three custom modules 
We need also a connection to Wordpress
More information upon request