1

It seems that there are two different Location objects:

  • global class Location extends SObject
  • global class System.Location

Because System is the default namespace, I am not sure how to refer to the SObject Location in my Apex code.

Example (in Location trigger):

Map<Id, Location> newLocations = (Map<Id, Location>) Trigger.newMap;

Incompatible types since an instance of Map<Id,SObject> is never an instance of Map<Id,System.Location>

Is there any way for me to reference the Location SObject?

3
  • I'm not aware of a standard Location object, nor do I see it in the documentation. Are you sure you have the right API name for Location?
    – sfdcfox
    Commented Aug 7, 2017 at 12:02
  • Yes I am sure. My trigger class is on "Location" SObject
    – Simonp
    Commented Aug 7, 2017 at 12:07
  • 2
    I'm really curious about this Location SObject. If I try to add a trigger on it in my org I get: Invalid type: Schema.Location Commented Aug 7, 2017 at 12:11

1 Answer 1

3

Whenever there's a conflict, you can usually rely on Schema to help you sort things out.

Map<Id, Schema.Location> locations = (Map<Id, Schema.Location>)Trigger.newMap;

However, this won't work if you define a class named "Schema", so make sure that you never, ever do that, unless you want to lose all access to the Schema methods, since it cannot be resolved any other way.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .