Developer Resources
Create Quote & Create Order Gl...
Validation & Error Handling
31 min
the ruby globalquoteserviceapi createquote() https //docs nue io/apex global methods and services method returns structured errors and warnings that enable programmatic error handling this is especially valuable for ai driven workflows where the system can self correct based on error codes response structure on failure when a request fails validation or encounters a business logic error, the response includes a failure status and a list of structured error messages ruby globalapitypes createquoteresponse response = ruby globalquoteserviceapi createquote(request); if (response status == 'failure') { for (ruby globalapitypes message err response errors) { system debug('severity ' + err errorcode); // "error" or "fatal" system debug('code ' + err errortype); // e g , "product quantity invalid" system debug('message ' + err message); // human readable description } } each ruby globalapitypes message contains field description errorcode severity level "error" for validation errors, "fatal" for unhandled exceptions errortype specific error code for programmatic handling (e g , "quote name required" ) message human readable description of the problem quote header validation errors these errors are returned when required quote header fields are missing or invalid 1\ missing quote name quote name required ruby globalapitypes createquoterequest request = new ruby globalapitypes createquoterequest(); request quote = new quote( opportunityid = oppid, // name is missing ruby subscriptionstartdate c = date today(), ruby subscriptionenddate c = date today() addmonths(12), ruby subscriptionterm c = 12, ruby subscriptiontermdimension c = 'month' ); request products = new list\<ruby globalapitypes productinput>{ product }; request iscommit = false; ruby globalapitypes createquoteresponse response = ruby globalquoteserviceapi createquote(request); system assertequals('failure', response status); // error errortype = 'quote name required', message = "the field 'name' is required " 2\ missing opportunityid quote opportunityid required request quote = new quote( name = 'no opportunity', // opportunityid is missing ruby subscriptionstartdate c = date today(), ruby subscriptionenddate c = date today() addmonths(12), ruby subscriptionterm c = 12, ruby subscriptiontermdimension c = 'month' ); ruby globalapitypes createquoteresponse response = ruby globalquoteserviceapi createquote(request); system assertequals('failure', response status); // error errortype = 'quote opportunityid required' 3\ negative subscription term quote subscriptionterm invalid request quote = new quote( opportunityid = oppid, name = 'negative term', ruby subscriptionstartdate c = date today(), ruby subscriptionterm c = 5, // invalid negative ruby subscriptiontermdimension c = 'month' ); ruby globalapitypes createquoteresponse response = ruby globalquoteserviceapi createquote(request); system assertequals('failure', response status); // error errortype = 'quote subscriptionterm invalid', message = "the value for subscriptionterm is invalid " 4\ zero subscription term quote subscriptionterm invalid request quote = new quote( opportunityid = oppid, name = 'zero term', ruby subscriptionstartdate c = date today(), ruby subscriptionterm c = 0, // invalid zero ruby subscriptiontermdimension c = 'month' ); ruby globalapitypes createquoteresponse response = ruby globalquoteserviceapi createquote(request); system assertequals('failure', response status); // error errortype = 'quote subscriptionterm invalid' 5\ null products list missing parameter request products = null; // no products provided ruby globalapitypes createquoteresponse response = ruby globalquoteserviceapi createquote(request); system assertequals('failure', response status); // error errortype = 'missing parameter', message = "missing field value products" 6\ empty products list missing parameter request products = new list\<ruby globalapitypes productinput>(); // empty list ruby globalapitypes createquoteresponse response = ruby globalquoteserviceapi createquote(request); system assertequals('failure', response status); // error errortype = 'missing parameter', message = "missing field value products" product validation errors these errors are returned when individual product inputs are invalid 7\ nonexistent sku when a sku does not match any product in the org, the entire request fails ruby globalapitypes productinput product = new ruby globalapitypes productinput(); product productsku = 'does not exist'; product uom = 'user/month'; product quantity = 10; request products = new list\<ruby globalapitypes productinput>{ product }; ruby globalapitypes createquoteresponse response = ruby globalquoteserviceapi createquote(request); system assertequals('failure', response status); // error message identifies the unrecognized sku 8\ empty string sku product sku or name required ruby globalapitypes productinput product = new ruby globalapitypes productinput(); product productsku = ''; // empty string product productname = ''; // also empty product uom = 'user/month'; product quantity = 10; ruby globalapitypes createquoteresponse response = ruby globalquoteserviceapi createquote(request); system assertequals('failure', response status); // error errortype = 'product sku or name required', // message = "either productsku or productname must be provided for each product " 9\ wrong uom business logic error when the product exists but no pricebookentry matches the specified https //docs nue io/unit of measures uoms ruby globalapitypes productinput product = new ruby globalapitypes productinput(); product productsku = 'nue platform'; product uom = 'widget/decade'; // no price book entry for this uom product quantity = 10; ruby globalapitypes createquoteresponse response = ruby globalquoteserviceapi createquote(request); system assertequals('failure', response status); // error errortype = 'business logic error', message = "no pricebook entry found " 10\ mix of valid and invalid products if any product in the request is invalid, the entire request fails there is no partial success ruby globalapitypes productinput validproduct = new ruby globalapitypes productinput(); validproduct productsku = 'nue platform'; validproduct uom = 'user/month'; validproduct quantity = 10; ruby globalapitypes productinput invalidproduct = new ruby globalapitypes productinput(); invalidproduct productsku = 'does not exist'; invalidproduct uom = 'user/month'; invalidproduct quantity = 5; request products = new list\<ruby globalapitypes productinput>{ validproduct, invalidproduct }; ruby globalapitypes createquoteresponse response = ruby globalquoteserviceapi createquote(request); system assertequals('failure', response status); // the valid product is not created the entire request is atomic product field validation these errors are returned when per product field overrides contain invalid values 11\ invalid billing period product billingperiod invalid ruby globalapitypes productinput product = new ruby globalapitypes productinput(); product productsku = 'nue platform'; product uom = 'user/month'; product quantity = 10; product billingperiod = 'biweekly'; // not a valid picklist value ruby globalapitypes createquoteresponse response = ruby globalquoteserviceapi createquote(request); system assertequals('failure', response status); // error errortype = 'product billingperiod invalid', // message = "the billingperiod value is invalid or not recognized available values include " 12\ zero subscription term product subscriptionterm invalid ruby globalapitypes productinput product = new ruby globalapitypes productinput(); product productsku = 'nue platform'; product uom = 'user/month'; product quantity = 10; product subscriptionterm = 0; // invalid must be > 0 ruby globalapitypes createquoteresponse response = ruby globalquoteserviceapi createquote(request); system assertequals('failure', response status); // error errortype = 'product subscriptionterm invalid', // message = "the value for subscriptionterm must be greater than 0 " 13\ invalid billing timing product billingtiming invalid ruby globalapitypes productinput product = new ruby globalapitypes productinput(); product productsku = 'nue platform'; product uom = 'user/month'; product quantity = 10; product billingtiming = 'sometime later'; // not a valid picklist value ruby globalapitypes createquoteresponse response = ruby globalquoteserviceapi createquote(request); system assertequals('failure', response status); // error errortype = 'product billingtiming invalid', // message = "the billingtiming value is invalid or not recognized available values include " bundle validation 14\ invalid add on product invalid addon product when an add on product is not in the https //docs nue io/product bundle configured product option list ruby globalapitypes productinput bundle = new ruby globalapitypes productinput(); bundle productsku = 'nue gem edition'; bundle uom = 'user/month'; bundle quantity = 5; ruby globalapitypes productinput invalidaddon = new ruby globalapitypes productinput(); invalidaddon productsku = 'unrelated product'; // not a valid option for this bundle bundle addons = new list\<ruby globalapitypes productinput>{ invalidaddon }; request products = new list\<ruby globalapitypes productinput>{ bundle }; ruby globalapitypes createquoteresponse response = ruby globalquoteserviceapi createquote(request); system assertequals('failure', response status); // error errortype = 'invalid addon product', // message identifies the product that is not in the bundle's option list 15\ currency mismatch pricebook entry mismatch when a bundle child's productoption references a https //docs nue io/price books in a different https //docs nue io/multiple currencies than the quote quote q = new quote( opportunityid = europpid, name = 'eur bundle mismatch', ruby subscriptionstartdate c = date today(), ruby subscriptionenddate c = date today() addmonths(12), ruby subscriptionterm c = 12, ruby subscriptiontermdimension c = 'month' ); q put('currencyisocode', 'eur'); request quote = q; ruby globalapitypes productinput bundle = new ruby globalapitypes productinput(); bundle productsku = 'bundle with usd only options'; bundle uom = 'user/month'; bundle quantity = 5; request products = new list\<ruby globalapitypes productinput>{ bundle }; ruby globalapitypes createquoteresponse response = ruby globalquoteserviceapi createquote(request); system assertequals('failure', response status); // error errortype = 'pricebook entry mismatch' warnings (non fatal) warnings are returned on successful requests ( status = 'succeed' ) they indicate potential issues that did not prevent quote creation but may warrant attention 16\ both discount percentage and amount product discount applied when both discount (percentage) and discountamount (currency) are set on a product, the percentage wins and a warning is returned ruby globalapitypes productinput product = new ruby globalapitypes productinput(); product productsku = 'nue platform'; product uom = 'user/month'; product quantity = 10; product discount = 20 0; // 20% discount product discountamount = 50 00; // also set amount will be ignored ruby globalapitypes createquoteresponse response = ruby globalquoteserviceapi createquote(request); system assertequals('succeed', response status); // warning errortype = 'product discount applied', // message explains that percentage takes precedence 17\ both header discount percentage and amount header discount applied same behavior at the header level when both quote ruby discount c (percentage) and quote ruby discountamount c are set, the percentage wins request quote = new quote( opportunityid = oppid, name = 'header discount conflict', ruby subscriptionstartdate c = date today(), ruby subscriptionenddate c = date today() addmonths(12), ruby subscriptionterm c = 12, ruby subscriptiontermdimension c = 'month', ruby discount c = 15 0, // 15% header discount ruby discountamount c = 200 00 // also set amount will be ignored ); ruby globalapitypes createquoteresponse response = ruby globalquoteserviceapi createquote(request); system assertequals('succeed', response status); // warning errortype = 'header discount applied' 18\ product overrides header product discount overrides header when a product has its own discount and the header also has a discount, the product level discount takes precedence for that line a warning is returned request quote = new quote( opportunityid = oppid, name = 'override test', ruby subscriptionstartdate c = date today(), ruby subscriptionenddate c = date today() addmonths(12), ruby subscriptionterm c = 12, ruby subscriptiontermdimension c = 'month', ruby discount c = 10 0 // 10% header discount ); ruby globalapitypes productinput product = new ruby globalapitypes productinput(); product productsku = 'nue platform'; product uom = 'user/month'; product quantity = 10; product discount = 25 0; // product discount overrides the 10% header discount request products = new list\<ruby globalapitypes productinput>{ product }; ruby globalapitypes createquoteresponse response = ruby globalquoteserviceapi createquote(request); system assertequals('succeed', response status); // warning errortype = 'product discount overrides header' // the line uses 25% discount, not the 10% header discount 19\ duplicate price tag duplicate price tag when the same https //docs nue io/price and discount tags is specified more than once on a product ruby globalapitypes pricetaginput tag1 = new ruby globalapitypes pricetaginput(); tag1 code = 'volume discount 10'; ruby globalapitypes pricetaginput tag2 = new ruby globalapitypes pricetaginput(); tag2 code = 'volume discount 10'; // same tag again ruby globalapitypes productinput product = new ruby globalapitypes productinput(); product productsku = 'nue platform'; product uom = 'user/month'; product quantity = 10; product pricetags = new list\<ruby globalapitypes pricetaginput>{ tag1, tag2 }; ruby globalapitypes createquoteresponse response = ruby globalquoteserviceapi createquote(request); system assertequals('succeed', response status); // warning errortype = 'duplicate price tag' // the tag is applied once; the duplicate is ignored complete error code reference error codes (fatal cause failure ) error code trigger message quote name required quote name is blank the field 'name' is required quote opportunityid required no opportunityid provided the field 'opportunityid' or opportunity json block is required quote accountid required no accountid resolvable the field 'accountid' is required quote subscriptionterm invalid quote ruby subscriptionterm c <= 0 the value for subscriptionterm is invalid missing parameter null or empty products list, missing iscommit, missing quote missing field value {field} product sku or name required both productsku and productname are blank either productsku or productname must be provided product quantity invalid null/negative quantity (root) or negative (add on) the value for product quantity is invalid or negative product billingperiod invalid unrecognized billing period value the billingperiod value is invalid or not recognized product billingtiming invalid unrecognized billing timing value the billingtiming value is invalid or not recognized product subscriptionterm invalid subscriptionterm <= 0 on a product the value for subscriptionterm must be greater than 0 product renewalterm invalid renewalterm <= 0 the value for renewalterm must be greater than 0 invalid input evergreen = true with subscriptionterm or enddate cannot set subscriptionterm or enddate when evergreen is true invalid addon product add on not in bundle's option list product is not a valid option for the specified bundle pricebook entry mismatch bundle child price book entry currency mismatch pricebookentry currency does not match quote currency business logic error no matching price book entry for product/uom/currency no pricebook entry found for the specified combination invalid argument conflicting field values conflicting field values between {field1} and {field2} warning codes (non fatal returned on succeed ) warning code trigger behavior product discount applied both discount and discountamount set on product percentage takes precedence header discount applied both ruby discount c and ruby discountamount c set on quote percentage takes precedence product discount overrides header product has its own discount when header discount exists product discount used for that line duplicate price tag same price tag specified twice on a product tag applied once; duplicate ignored default value applied a default value was applied for a missing field informational best practices always check response status before accessing response data data is null when status = 'failure' inspect warnings even on succeed warnings indicate potential issues such as discount conflicts, duplicate tags, or applied defaults that may not match your intent use errortype (not errorcode ) for programmatic handling errorcode contains the severity level ( "error" , "warning" ), while errortype contains the specific error code (e g , "product quantity invalid" ) for ai integrations parse errortype to auto correct and retry the structured error codes are designed for programmatic consumption an ai system can map each errortype to a correction strategy product sku or name required look up the correct sku product billingperiod invalid check the available values listed in the error message business logic error with "no pricebook entry found" try a different uom or currency, or create the missing price book entry quote subscriptionterm invalid ensure term is a positive number validate in preview mode first use iscommit = false to catch all errors before committing this avoids partial state from failed commits handle multiple errors a single request can return multiple errors (e g , missing quote name and invalid product quantity) process all errors before retrying rather than fixing one at a time
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.