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.

Example

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

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

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.

//fetch Service Appointment record(s)
Double longitude = 32.077213;
Double latitude = 34.792759;
    List<FSL__Polygon__c> relevantPolygons = 
FSL.PolygonUtils.getAllPolygonsByLatLong
(longitude,latitude);
    system.debug(relevantPolygons);