3

I'm trying a library that acts like an object factory. It works with serialization, so it is possible to specify formula fields without DML, which is pretty handy with tests.

My issue is that I'm trying to write a class that requires the Quote type. The apex compiler throws me the following error when using Quote.class:

Invalid field class for SObject Quote

But Opportunity.class, Account.class and even QuoteLineItem.class work just fine. Any idea why? Is it not possible to get the quote type? Or is there another way of doing it?

1 Answer 1

5

You have a variable named 'Quote' in your variable scope. Do not do this.

Quote quote = new Quote();
System.debug(quote.class); // compile-fail

It works if you avoid naming variables after class names:

Quote theQuote = new Quote();
System.debug(Quote.class); // outputs Quote

You can still refer to it correctly if you use the Schema namespace, though:

Quote quote = new Quote();
System.debug(schema.quote.class); // Outputs Quote
3
  • Are you a wizard!? Hahaha, that was it. There was a variable on the test class called "quote". Using the Schema namespace worked. Feb 5, 2018 at 16:41
  • 1
    @RenatoOliveira Let's just say that many of my answers to questions like this come from personal experience. 😅
    – sfdcfox
    Feb 5, 2018 at 16:52
  • Renato, sfdcfox is too modest : he is a wizard !
    – altius_rup
    Feb 5, 2018 at 21:37

You must log in to answer this question.

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