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
Dev ListingOrgDev ListingOrg 

Enable Quotes object using Apex Code

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 ??

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

Can we put some code in "Post Install Script"? How can we use Metadata in our apex code for enable Quotes when in install package in my customer's account.
Piyush Kumar 58Piyush Kumar 58

Use this code to enable Quotes in your org. I was write this code for enable Quotes in my developer org:-

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);


If you face any issue then let me know.

Piyush Kumar 58Piyush Kumar 58
NO We can not enable quotes through post install script . Because we enable Quotes throgh metadata api and in this process Session Id is required for this. We can not access Session Id through post install script or any outher future method.