System.Location confused with new Location entity (Schema.Location)

Issue #1627 resolved
Michael Hoefer created an issue

We have a new entity called Location (Schema.Location), which conflicts with the apex object Location (System.Location)

Repro:

API version 48.0

insert new Schema.Location(Name = 'California');   

Result:

Syntax/parse error: Expected type [SObject, List<SObject>]; found [Location, Schema.Location]

Using just new Location() should not and does not work. But Schema.Location should work, does compile in SFDC, but shows the error in IC.

Comments (17)

  1. Scott Wells repo owner

    Thanks, Michael. These types of order-of-precedence for symbol resolution--especially when implicit namespaces like System and Schema come into play--can be tricky. I'll take a look at the resolution strategy shortly and update it accordingly.

  2. Scott Wells repo owner

    Fix committed for inclusion in the next build (currently targeting Thursday morning).

  3. Scott Wells repo owner

    Michael, this wasn't quite addressed in the previous build. I've implemented some changes for the next one that get much, much closer. I've verified those changes with System.Site vs Schema.Site, but I don't have access to an org with the Schema.Location object. Is there an easy way to spin up a scratch org with that object via features/settings? I'd like to see how these changes hold up with that object as well if possible.

  4. Michael Hoefer reporter

    Hey Scott. You can use the "WorkplaceCommandCenterUser" feature. This enables the new Work.com employee experience entities, and pulls in Location as well.

  5. Scott Wells repo owner

    Thanks, Michael. I'll set one up and make sure it takes care of this resolution ambiguity.

  6. Scott Wells repo owner

    Created a scratch org with that setting. With the changes I've made for the next feature build, this all works properly:

    insert new Schema.Location(Name = 'California');
    Location loc = Location.newInstance(10.0, 20.0);
    System.debug(loc.getLatitude());
    

    I was concerned that insert new Location(Name = 'California') would also need to resolve to Schema.Location, but turns out that both IC2 and the Apex compiler resolve that as System.Location, so all good there as long as you qualify the SObject as Schema.Location even though Schema is an otherwise implicit namespace.

    Because of the release of the 2021.1 JetBrains IDEs this week, the next feature release will be next week.

  7. Scott Wells repo owner

    Another dumb question for you, Michael. Can I enable this feature in an existing DE org? If so, any tips on how to do so?

  8. Michael Hoefer reporter

    It should already be available on DE orgs by default. Are you not seeing it on a newish one?

  9. Scott Wells repo owner

    Oh, this is my pet DE org from 5-6 years ago. I have perhaps 3-4 static orgs with various things deployed to them, and of course another 5-6 scratch orgs with other test projects such as NPSP, fflib, etc. I just happen to be very fond of this particular one and wanted to have the feature enabled in it if possible. However, I don't see the Schema.Location SObject, nor do I see anywhere to turn on anything Work.com related. No big thing if I can't in this old org, though.

  10. Michael Hoefer reporter

    Yep, that makes sense. When new licenses are added to the DE template it doesn’t affect existing orgs, only new ones. We exposed Location with the Work.com feature last Summer. It can be enabled manually though, if you share the org id I can get that done for you.

  11. Scott Wells repo owner

    Sure, I'll take you up on that. The org ID is 00D2E000001HHwOUAW. Let me know if you need anything else. Thanks!

  12. Log in to comment