PolygonUtils Class

Represents the result of using the getTerritoryIdByPolygons method to return a service territory record ID using latitude and longitude geolocation values.

Namespace 

FSL

Usage 

Before calling the PolygonUtils class, make sure that you have existing map polygon records that are associated with a service territory.

If Base service appointment territories on polygons is enabled, global actions consume this class to populate the Service Territory field on service appointments. When standard FSL Global Actions are not being used, you can use the getTerritoryIdByPolygons method to populate the Service Territory lookup field on objects.

If getTerritoryIdByPolygons doesn’t find a territory it returns null.

For more information, see Create and Manage Map Polygons.

PolygonUtils Methods 

PolygonUtils includes the following static method.

getTerritoryIdByPolygons(longitude, latitude) 

Returns a service territory record ID from longitude and latitude values.

Signature 

static Id getTerritoryIdByPolygons(Double longitude, Double latitude)

Parameters 

longitude

Type: Double

Required. The longitude value of the geolocation to be used to retrieve a service territory record ID via Polygon Classification.

latitude

Type: Double

Required. The latitude value of the geolocation to be used to retrieve a service territory record ID via Polygon Classification.

Return Value 

Type: Id

Usage 

This method returns a service territory record ID from longitude and latitude values. If a service appointment’s geolocation matches more than one polygon, the appointment is assigned to either the highest or lowest-level territory in the hierarchy depending on your settings.

Example 

This example retrieves a service territory record ID using latitude and longitude geolocation fields.

1//fetch Service Appointment record(s)
2List<ServiceAppointment> sas = [select id, latitude, longitude from serviceappointment where appointmentnumber = 'SA-3600' limit 1];
3If(!sas.isEmpty()){
4    //retrieve the service territory record id from the getTerritoryIdByPolygons method using geolocation fields from the first appointment in the list
5    Id ServiceTerritoryId = FSL.PolygonUtils.getTerritoryIdByPolygons(double.valueOf(sas[0].longitude),double.valueOf(sas[0].latitude));
6    system.debug(ServiceTerritoryId);
7}

getAllPolygonsByLatLong(longitude, latitude) 

Returns a list of IDs of all matching polygons that include the point with the longitude and latitude values.

Signature 

static List getAllPolygonsByLatLong(Double longitude, Double latitude)

Parameters 

longitude

Type: Double

Required. The longitude value of the geolocation to be used to retrieve a service territory record ID using polygon classification.

latitude

Type: Double

Required. The latitude value of the geolocation to be used to retrieve a service territory record ID using polygon classification.

Return Value 

Type: List <Id>

Usage 

This method returns a list of polygon record IDs from longitude and latitude values. The method doesn’t include sharing.

Example 

This example retrieves a list of relevant polygons that include the point with the longitude and latitude values.

1//fetch Service Appointment record(s)
2Double longitude = 32.077213;
3Double latitude = 34.792759;
4    List<FSL__Polygon__c> relevantPolygons = 
5FSL.PolygonUtils.getAllPolygonsByLatLong
6(longitude,latitude);
7    system.debug(relevantPolygons);