function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Michael DsozaMichael Dsoza 

Enable Quote sObject from Apex Code


I am using Quote sObject in Rest API call but in new instance, I have to enable Quote sObject manually by clicking checkbox in Setup -> Quote -> Settings -> Enable Quote.

How can I enable it from Apex Code ??

I tried to find Quote sObject (before enable) in Schema.getGlobalDescribe().values() but there is NO such Quote sObject Type.

Please let me know how can I enable it from Apex Code.

Hi Michael - You can't enable/disable directly from the Apex code. The only option other than the manual step is through Metadata API, you can do that. Here is the link
Deepak Kumar ShyoranDeepak Kumar Shyoran
As explained by Karanraj metadata can only way to achieve that otherwise there is no such way to Enable Quote from Apex Code.

Piyush Kumar 58Piyush Kumar 58
You Can enable Quotes like this :-
public class EnableQuotes {  

    public void fetch()
        HttpRequest request = new HttpRequest();
        request = new HttpRequest();
        request.setHeader('Content-Type', 'text/xml');
        request.setHeader('SOAPAction', 'update');   			 
         String b = '<?xml version="1.0" encoding="UTF-8"?>';
                b += '<soapenv:Envelope xmlns:soapenv="" xmlns:xsd="" xmlns:xsi="">';
                b += '<soapenv:Header>';
                b += '<ns1:SessionHeader soapenv:mustUnderstand="0" xmlns:ns1="">';
                b += '<ns1:sessionId>' + UserInfo.getSessionId() + '</ns1:sessionId>';
                b += '</ns1:SessionHeader>';
                b += '</soapenv:Header>';
                b += '<soapenv:Body>';
                b += '<update xmlns="">';
                b += '<UpdateMetadata>';
                b += '<currentName>QuoteSettings</currentName>';

                b += '<metadata xsi:type="ns2:QuoteSettings" xmlns:ns2="">';
            	b += '<fullName>QuoteSettings</fullName>';
            	b += '<enableQuote>true</enableQuote>';
                b += '</metadata>';
                b += '</UpdateMetadata>';
                b += '</update>';
                b += '</soapenv:Body>';
                b += '</soapenv:Envelope>';
        //request.setHeader('Authorization', 'OAuth ' + SESSION_ID);

        String body = (new Http()).send(request).getBody();
        system.debug('Hello from body'+body);