[SalesForce] Trying to create QuoteDocument via API failes

I'm working on a PE with API enabled and I'm trying to create a QuoteDocument.
For some reason this failed with error:

sObject type 'QuoteDocument' is not supported. If you are attempting
to use a custom object, be sure to append the '__c' after the entity
name. Please reference your WSDL or the describe call for the
appropriate names.

This is the JS on my VF page that is trying to do the creation:

<script>
        function uploadQuoteDocument( filecontent,  quoteId) {
            var quoteDocument  = new sforce.SObject('QuoteDocument');
            quoteDocument.Document = filecontent;
            quoteDocument.QuoteId = quoteId;
            var result = sforce.connection.create([quoteDocument]);
            if (result[0].getBoolean("success")) {
                alert('Quote PDF successfully generated');
                window.location.href = '/{!Quote.Id}';
            } else {
                console.log(result);
                alert('Quote PDF generation failed');
            }
        }
<script>

Does anyone know why am I getting this error?

Best Answer

Interesting... I have some ideas, too much to put in a comment.

Add sforce.debug.trace=true; to the beginning of your method.

Regarding the API version don't be so sure you're using v. 26, check https://stackoverflow.com/q/23556030/313628.

Any special reason why it has to be done in javascript and not pure VF + apex?

insert new QuoteDocument(
    Document = Blob.toPDf('Test PDF content'),
    QuoteId = '0Q070000000OjV9'
);

Some <apex:input> field with should work too and be much cleaner... And if you don't want an inputField but JS way is giving you hard time you could still try with marking an apex method as webservice (oldschool way) or remoteaction. Server-side code should bypass any weird "no-Profiles-but-still" security settings in PE (I've recently had a security review and had to slap CRUD checks all over the place. Turns out managed code was bypassing the PE's "security by page layout" just fine like in orgs that really have Profiles).

Last but not least: what are you getting when you execute this (or matching describe operation in Ajax toolkit)?

Schema.DescribeSObjectResult dsr = Schema.SobjectType.QuoteDocument;
System.debug(dsr.isAccessible() + ', ' + dsr.isCreateable());
Related Topic