+ Start a Discussion
ClaiborneClaiborne 

sObjectType.newSObject() with Quote Object

This statement works:
        Account acct = (Account)Account.sObjectType.newSObject(null, true);

This one does not. 
        Quote newQuote = (Quote)Quote.sObjectType.newSObject(null, true);

Any ideas
Peter FribergPeter Friberg
Strange, I just ran this conde in my Sandbox and it worked like charm:
Account acct = (Account)Account.sObjectType.newSObject(null, true);
system.debug('acc=' + acct);

Quote qt = (Quote)Quote.sObjectType.newSObject(null, true);
system.debug('quote=' + qt);
What is the error?
ClaiborneClaiborne
I am getting a message that sObjectType is not a valid field for Quote. Very weird. It will not save the apex class because of the error.
karthikeyan perumalkarthikeyan perumal
Hello, 

Have you Enabled Quotes Settings like below, so that that you able to access the Quote object in you class.  kindly refer the image below. by default its not enabled. we have to enable it manually. 

User-added image

Hope this will help you. 

Thanks
karthik
 
ClaiborneClaiborne
Here is the code, exactly:
 
        Account acct = (Account)Account.sObjectType.newSObject(null, true);
        Quote newQuote = (Quote)Quote.sObjectType.newSObject(null, true);

The second line, with Quote is flagged with error:

Invalid field sObjectType for sObject Quote

And Quotes are enabled for the org.
 
karthikeyan perumalkarthikeyan perumal
Hello, 

your code is working fine in class and execute_anonymous_apex window as well. 

Thanks
karthik
 
karthikeyan perumalkarthikeyan perumal
post your error screenshot and full code of the apex class as well.so that we can find that 
 
ClaiborneClaiborne
Full code is over 1600 lines. It works for me in a simple class. I will have to start removing stuff to see where it breaks. The failure is in the init method.
ClaiborneClaiborne
OK, I solved the problem.

In the apex class, I had a global variable, also called quote. It was defined as:

public Quote quote { get; set; }

This worked just fine. I statements like quote = new Quote(); and quote = [select . . . from Quote where Id = : qid];

But you cannot use the statement:

Quote newQuote = (Quote)Quote.sObjectType.newSObject(null, true);

It throws an error and will not save.

The solution was to change my local variable quote to myQuote. So the initialization statement became:

public Quote myQuote { get; set; }

Thanks everyone for helping out.