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
jeremyyjeremyy 

Fields of type Geolocation break dynamic Apex

Given a field name 'Geolocation__c' of type Geolocation, the following code produces 'System.TypeException: Data type not supported':
SObject contactSob = new Contact();
System.debug(contactSob.get('Geolocation__c'));
This seems to have broken a lot of our code. Any ideas what's causing this, or a workaround?

Punam AgrawallaPunam Agrawalla
Hi Jeremyy,

Geolocation type field cannot be directly used.
we have to use these field like :

SObject contactSob = new Contact();
System.debug(contactSob.get('Geolocation__latitude__s'));

We need to divide the field with latitude and longitude.

if you want langitude then use like:

System.debug(contactSob.get('Geolocation__longitude__s'));

I think it will help you. please try this.

Thanks

jeremyyjeremyy
I'm aware of how to use geolocation fields. However, the problem is that the existence of a geolocation field breaks almost all dynamic Apex code that *correctly* uses dynamic apex to retrieve fields at runtime and operate on them. A minor regression, wouldn't you say? 

What I'd like to know is if salesforce is planning on addressing this, or is there a reasonable workaround?