Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ghosted SObject with missing standard type #315

Open
pwrightcertinia opened this issue Jan 17, 2025 · 2 comments
Open

Ghosted SObject with missing standard type #315

pwrightcertinia opened this issue Jan 17, 2025 · 2 comments
Labels
bug Something isn't working

Comments

@pwrightcertinia
Copy link
Contributor

Example

Unknown field or type 'Name' on 'Schema.SObjectType.namespace__customObject__c.Fields'

We have standard fields on GhostSObjectDeclaration including the Name field so it should be finding it, but isn't.

@pwrightcertinia pwrightcertinia added the bug Something isn't working label Jan 17, 2025
@pwrightcertinia
Copy link
Contributor Author

Managed to repro this in GhostPackageTest:

test("Ghost package with custom sobject standard field reference") {
    FileSystemHelper.run(
      Map(
        "sfdx-project.json" ->
          """{
            |"namespace": "pkg",
            |"packageDirectories": [{"path": "pkg"}],
            |"plugins": {"dependencies": [{"namespace": "ghosted"}]}
            |}""".stripMargin,
        "pkg/Dummy.cls" -> "public class Dummy { void func() { String name = Schema.SObjectType.ghosted__myObject__c.Fields.Name; } }"
      )
    ) { root: PathLike =>
      createOrg(root)
      assert(packagedClass("pkg", "Dummy").get.dependencies().isEmpty)
      assert(
        getMessages(
          root.join("pkg").join("Dummy.cls")
        ) == "Missing: line 1 at 49-100: Unknown field or type 'Name' on 'Schema.SObjectType.ghosted__myObject__c.Fields'\n"
      )
    }
  }

@pwrightcertinia
Copy link
Contributor Author

pwrightcertinia commented Jan 17, 2025

It would seem to be because the SchemaSObjectType class has nothing in ghostedSobjectFields / sobjectfields. the main fields are created with type resolver and presumably a "real" sobject type returned by the type resolver would include the standard fields.

Unfortunately the type resolver does not return anything when searching for the ghost object. Can fix this in two places:

  • Prevent the error from displaying at all by checking if inputType (the object) is ghosted too - which stops dot expression from doing missing errors on fields of ghosted objects in the specific case.
  • Add standard fields to ghostedSobjectfields on SchemaSObjectType so they get picked up only when its a ghosted type.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant