Creating Orders (Create Order Global Method)
18 min
the https //docs nue io/create quotes and orders method ( ruby globalorderserviceapi createorder https //docs nue io/apex global methods and services ) mirrors the create quote method but creates order + orderitem records instead of quote + quotelineitem method signature ruby globalapitypes createorderresponse response = ruby globalorderserviceapi createorder(request); class ruby globalorderserviceapi method global static ruby globalapitypes createorderresponse createorder(ruby globalapitypes createorderrequest req) key differences from create quote aspect create quote create order entry class ruby globalquoteserviceapi ruby globalorderserviceapi request type ruby globalapitypes createquoterequest ruby globalapitypes createorderrequest header sobject quote order line item sobject quotelineitem orderitem response type ruby globalapitypes createquoteresponse ruby globalapitypes createorderresponse response dto ruby globalapitypes quotedto ruby globalapitypes orderdto line dto ruby globalapitypes quotelineitemdto ruby globalapitypes orderitemdto required opportunityid yes no required accountid via opportunity yes (directly on order accountid or via request accountid ) status field order status (defaults to 'draft' ) effectivedate order effectivedate (defaults to end date or start date) request type createorderrequest ruby globalapitypes createorderrequest request = new ruby globalapitypes createorderrequest(); field type required description iscommit boolean yes true = persist to database; false = pricing preview only order order yes the order sobject with header fields products list\<ruby globalapitypes productinput> yes one or more products to add to the order pricetags list\<ruby globalapitypes pricetaginput> no header level price/discount tags applied to all products accountid id no alternative to order accountid if both are set, they must match order header fields field type required default description accountid id yes required unless request accountid is provided pricebook2id id no standard price book pricebook for https //docs nue io/price books resolution ruby subscriptionstartdate c date no date today() subscription start date ruby subscriptionenddate c date no calculated from start + term subscription end date ruby subscriptionterm c decimal no calculated from start/end dates subscription term ruby subscriptiontermdimension c string no 'month' or 'year' ( https //docs nue io/understanding subscription term basis and proration ) effectivedate date no end date or start date order effective date status string no 'draft' order status use cases 1\ basic order creation (preview) create an order with a single product in preview mode ruby globalapitypes createorderrequest request = new ruby globalapitypes createorderrequest(); order ord = new order( accountid = accountid, ruby subscriptionstartdate c = date today(), ruby subscriptionenddate c = date today() addmonths(12), ruby subscriptionterm c = 12, ruby subscriptiontermdimension c = 'month', status = 'draft', effectivedate = date today() addmonths(12) ); request order = ord; ruby globalapitypes productinput product = new ruby globalapitypes productinput(); product productsku = 'nue platform'; product uom = 'user/month'; product quantity = 10; request products = new list\<ruby globalapitypes productinput>{ product }; request iscommit = false; ruby globalapitypes createorderresponse response = ruby globalorderserviceapi createorder(request); system assertequals('succeed', response status); system assertequals(null, response data order id, 'order should not have an id in preview mode'); system assertequals(1, response data lineitems size()); // access pricing on the line item ruby globalapitypes orderitemdto linedto = response data lineitems\[0]; orderitem oi = linedto orderitem; system debug('sku ' + oi product2 stockkeepingunit); system debug('list price ' + oi ruby listprice c); system debug('total price ' + oi ruby totalprice c); 2\ order with bundles https //docs nue io/product bundle products use the same productinput structure as quotes, including the addons list for optional add on products ruby globalapitypes createorderrequest request = new ruby globalapitypes createorderrequest(); order ord = new order( accountid = accountid, ruby subscriptionstartdate c = date today(), ruby subscriptionenddate c = date today() addmonths(12), ruby subscriptionterm c = 12, ruby subscriptiontermdimension c = 'month', status = 'draft', effectivedate = date today() addmonths(12) ); request order = ord; ruby globalapitypes productinput bundle = new ruby globalapitypes productinput(); bundle productsku = 'nue gem edition'; bundle uom = 'user/month'; bundle quantity = 5; ruby globalapitypes productinput addon = new ruby globalapitypes productinput(); addon productsku = 'usb security key'; bundle addons = new list\<ruby globalapitypes productinput>{ addon }; request products = new list\<ruby globalapitypes productinput>{ bundle }; request iscommit = false; ruby globalapitypes createorderresponse response = ruby globalorderserviceapi createorder(request); system assertequals('succeed', response status); // response includes parent bundle + bundled items + add ons 3\ order with discounts both header level and product level discounts work identically to quotes order ord = new order( accountid = accountid, ruby subscriptionstartdate c = date today(), ruby subscriptionenddate c = date today() addmonths(12), ruby subscriptionterm c = 12, ruby subscriptiontermdimension c = 'month', status = 'draft', effectivedate = date today() addmonths(12), ruby discount c = 10 0 // 10% header discount ); request order = ord; ruby globalapitypes productinput product = new ruby globalapitypes productinput(); product productsku = 'nue platform'; product uom = 'user/month'; product quantity = 10; product discount = 25 0; // product level discount overrides header request products = new list\<ruby globalapitypes productinput>{ product }; 4\ order with price tags https //docs nue io/price and discount tags use the same pricetaginput structure ruby globalapitypes pricetaginput tag = new ruby globalapitypes pricetaginput(); tag code = 'volume discount 10'; ruby globalapitypes productinput product = new ruby globalapitypes productinput(); product productsku = 'nue platform'; product uom = 'user/month'; product quantity = 100; product pricetags = new list\<ruby globalapitypes pricetaginput>{ tag }; request products = new list\<ruby globalapitypes productinput>{ product }; 5\ committed order set iscommit = true to persist the order and orderitems to the database request iscommit = true; ruby globalapitypes createorderresponse response = ruby globalorderserviceapi createorder(request); system assertequals('succeed', response status); system assertnotequals(null, response data order id, 'order should have a salesforce id'); // re query to confirm persistence order savedorder = \[select id, status, ruby totalprice c from order where id = \ response data order id]; system debug('order ' + savedorder id + ' | status ' + savedorder status + ' | total ' + savedorder ruby totalprice c); feature parity with create quote all features available in ruby globalquoteserviceapi createquote() are also available in ruby globalorderserviceapi createorder() feature supported standalone products yes bundles with bundled items yes optional and required add ons yes https //docs nue io/dynamic product options yes https //docs nue io/price and discount tags yes header level discounts yes product level discounts yes https //docs nue io/multi attribute pricing yes https //docs nue io/quantity tier attributes for price tags yes custom pricing attributes yes https //docs nue io/multiple currencies yes per product term overrides yes evergreen subscriptions yes auto renew yes custom fields on header yes (via put() ) preview mode ( iscommit = false ) yes commit mode ( iscommit = true ) yes structured error and warning messages yes the only differences are the entry point class, request/response types, and the header sobject ( order vs quote ) when to use create order vs create quote scenario recommended api deals requiring review/approval before fulfillment create quote quote to order conversion workflow create quote, then ruby globalquoteservice generateorders() self service portals or e commerce checkout create order automated renewals from external systems create order system to system integrations (erp, billing) create order batch order creation from imported data create order proof of concept pricing exploration either (use preview mode) after order creation once an order is created, it can be activated to generate subscriptions, entitlements, and assets via the standard nue activation flow related services for managing orders after creation service method description ruby globalorderservice recalculate(orderid) recalculate pricing on a draft order ruby globalorderservice reapplypricetags(orderid) reload applicable price tags on a draft order ruby globalorderservice cancelactiveorders(orderids) cancel active orders error handling error handling works identically to the create quote api the response includes the same status , errors , and warnings structure ruby globalapitypes createorderresponse response = ruby globalorderserviceapi createorder(request); if (response status == 'failure') { for (ruby globalapitypes message err response errors) { system debug('error \[' + err errortype + '] ' + err message); } } if (response warnings != null) { for (ruby globalapitypes message w response warnings) { system debug('warning \[' + w\ errortype + '] ' + w\ message); } } all error codes and warning codes documented in apply to the create order api as well, with the exception of quote specific codes (e g , quote opportunityid required ) the order specific validation requires accountid instead of opportunityid
Have a question?
Get answers fast with Nue’s intelligent AI, expert support team, and a growing community of users - all here to help you succeed.
To ask a question or participate in discussions, you'll need to authenticate first.