Activity › Forums › Salesforce® Discussions › Enable Quotes and Order using Post install Script
Tagged: CRUD Operation, Metadata API, Order, Post Install Script, Quote, Salesforce Force.com, SessionId
-
Enable Quotes and Order using Post install Script
Posted by Bhavesh on March 29, 2016 at 4:33 AMHello Team,
I want to enable Quotes and Order object using Post Install Script. Is it possible?
Abhinav replied 10 years ago 3 Members · 9 Replies -
9 Replies
-
Hi Bhavesh,
We can only enable the Quotes and Order settings either by point and click or by using Metadata APIs. See the below link –
https://developer.salesforce.com/docs/atlas.en-us.api_meta.meta/api_meta/meta_quotessettings.htm
https://developer.salesforce.com/docs/atlas.en-us.api_meta.meta/api_meta/meta_ordersettings.htmWe can use the above links info in apex class like below
HTTP h = new HTTP();
HTTPRequest req = new HTTPRequest();
req.setMethod(‘POST’);
req.setHeader(‘Content-Type’, ‘text/xml’);
req.setHeader(‘SOAPAction’, ‘create’);String b = ‘‘;
b += ‘‘; ‘;
b += ‘true ‘;
b += ‘
req.setBody(b);
req.setCompressed(false);
req.setEndpoint(‘https://na12-api.salesforce.com/services/Soap/m/25.0’);
HTTPResponse resp = h.send(req);In apex, we can do only simple CRUD operations using Metadata APIs.
- [adinserter block='9']
-
Hi naman,
I have managed package in which Opportunity, Quotes and Order I have. Now when customer is installing it at that time it is giving the error that please enable quotes.
I want that when customer installed this managed package at that time if Quotes is not enable , enable it by some code without knowing to customer.
Is it possible?
-
Yes it is possible.
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);-
This reply was modified 10 years, 1 month ago by
Abhinav.
-
This reply was modified 10 years, 1 month ago by
-
The above code is to enable the quote in the Org. But we cannot get the SessionId in the post install script. Please see the link below :- https://developer.salesforce.com/docs/atlas.en-us.packagingGuide.meta/packagingGuide/apex_post_install_script.htm#apex_post_install_script
-
Yeah, in place of using the above code in the post install script as we do not get the session Id in the post install script, we can either make one tab in our app so that on the click of the tab the above code runs and the quote gets enabled or we can make one custom button on the object such that on the click of that button we can enable the quote using the above code.
-
Yeah, that may be same but i have not worked for order. I did for quote enabled.
Log In to reply.