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

Hi,

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.

Thanks 
Michael
KaranrajKaranraj
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 http://www.salesforce.com/us/developer/docs/api_meta/Content/meta_quotessettings.htm
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.setEndpoint('https://ap2.salesforce.com/services/Soap/m/31.0');
        request.setMethod('POST');  
        request.setHeader('Content-Type', 'text/xml');
        request.setHeader('SOAPAction', 'update');   			 
         String b = '<?xml version="1.0" encoding="UTF-8"?>';
                b += '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">';
                b += '<soapenv:Header>';
                b += '<ns1:SessionHeader soapenv:mustUnderstand="0" xmlns:ns1="http://soap.sforce.com/2006/04/metadata">';
                b += '<ns1:sessionId>' + UserInfo.getSessionId() + '</ns1:sessionId>';
                b += '</ns1:SessionHeader>';
                b += '</soapenv:Header>';
                b += '<soapenv:Body>';
               
                b += '<update xmlns="http://soap.sforce.com/2006/04/metadata">';
                b += '<UpdateMetadata>';
                b += '<currentName>QuoteSettings</currentName>';

                b += '<metadata xsi:type="ns2:QuoteSettings" xmlns:ns2="http://soap.sforce.com/2006/04/metadata">';
                
            	b += '<fullName>QuoteSettings</fullName>';
            	b += '<enableQuote>true</enableQuote>';
               
                b += '</metadata>';
                b += '</UpdateMetadata>';
                b += '</update>';
                b += '</soapenv:Body>';
                b += '</soapenv:Envelope>';
            request.setBody(b);
            request.setCompressed(false);
     
        //request.setHeader('Authorization', 'OAuth ' + SESSION_ID);

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

}