GlobalHeaderObjectService - UpdateStartDate Method
23 min
overview the globalheaderobjectservice provides a comprehensive set of global methods for updating quote start dates directly this service automatically recalculates end dates and updates all associated line items when the start date is changed key features automatically recalculates quote end dates based on subscription terms updates all associated quotelineitem start and end dates integrates with the pricing engine for accurate date calculations supports both single and bulk operations includes validation and error handling method 1 simple quote start date update use case update a single quote's start date when you have the quote id and new date example code // initialize the service globalheaderobjectservice service = new globalheaderobjectservice(); // get your quote id (example) id quoteid = '0q0xx0000000001'; // replace with actual quote id // set the new start date date newstartdate = date newinstance(2024, 1, 15); // january 15, 2024 // update the quote start date service updatestartdate(quoteid, newstartdate); system debug('quote start date updated successfully!'); what happens behind the scenes the service queries the quote and all its quotelineitems sends the data to the ruby pricing engine for recalculation updates the quote's subscriptionstartdate c and subscriptionenddate c updates all quotelineitem subscriptionstartdate c and subscriptionenddate c fields saves all changes to the database quick example update quote start date to today use case set a quote's start date to the current date commonly used for immediate activation or "start now" scenarios // initialize the service globalheaderobjectservice service = new globalheaderobjectservice(); // get your quote id id quoteid = '0q0xx0000000001'; // replace with actual quote id // update quote to start today service updatestartdate(quoteid, date today()); system debug('quote start date set to today ' + date today()); alternative using system today() // both date today() and system today() work the same way globalheaderobjectservice service = new globalheaderobjectservice(); service updatestartdate(quoteid, system today()); common scenario start quote immediately after approval public static void startquoteimmediately(id quoteid) { try { globalheaderobjectservice service = new globalheaderobjectservice(); // set start date to today service updatestartdate(quoteid, date today()); system debug('quote ' + quoteid + ' is now active starting today!'); } catch (exception e) { system debug('failed to activate quote ' + e getmessage()); throw e; } } method 2 bulk quote start date updates use case update multiple quotes' start dates in a single operation for better performance example code // initialize the service globalheaderobjectservice service = new globalheaderobjectservice(); // create update requests for multiple quotes list\<globalheaderobjectstartdateupdate> updaterequests = new list\<globalheaderobjectstartdateupdate>(); // add first quote update updaterequests add(new globalheaderobjectstartdateupdate( '0q0xx0000000001', // quote id date newinstance(2024, 2, 1) // new start date february 1, 2024 )); // add second quote update updaterequests add(new globalheaderobjectstartdateupdate( '0q0xx0000000002', // quote id date newinstance(2024, 2, 15) // new start date february 15, 2024 )); // add third quote update updaterequests add(new globalheaderobjectstartdateupdate( '0q0xx0000000003', // quote id date newinstance(2024, 3, 1) // new start date march 1, 2024 )); // execute bulk update service updatestartdate(updaterequests); system debug('all quotes updated successfully!'); performance benefits single database transaction for all updates reduced api calls to the pricing engine better governor limit management improved performance for large scale operations method 3 quote start date update with old date validation use case update quote start date with validation against the current start date to ensure data integrity example code // initialize the service globalheaderobjectservice service = new globalheaderobjectservice(); // query the quote to get current start date quote currentquote = \[select id, nue subscriptionstartdate c from quote where id = '0q0xx0000000001']; // create update request with old date validation globalstartdateupdatewitholdstartdate updaterequest = new globalstartdateupdatewitholdstartdate( currentquote id, // quote id currentquote nue subscriptionstartdate c, // current start date date newinstance(2024, 4, 1) // new start date april 1, 2024 ); // execute update with validation service updatestartdate(updaterequest); system debug('quote start date updated with validation!'); when to use this method when you need to ensure the quote hasn't been modified by another process for critical business operations requiring data integrity validation when implementing optimistic locking patterns in multi user environments to prevent conflicts method 4 advanced quote update with object manipulation use case update quote start date when you already have quote and quotelineitem objects in memory and want to manipulate them directly example code // initialize the service globalheaderobjectservice service = new globalheaderobjectservice(); // query quote and its line items quote quotetoupdate = \[select id, nue subscriptionstartdate c, nue subscriptionenddate c from quote where id = '0q0xx0000000001']; list\<quotelineitem> lineitemstoupdate = \[select id, nue subscriptionstartdate c, nue subscriptionenddate c, quoteid, product2id, quantity from quotelineitem where quoteid = \ quotetoupdate id]; // create update request with objects list\<globalstartdateupdatewithobjects> updaterequests = new list\<globalstartdateupdatewithobjects>(); updaterequests add(new globalstartdateupdatewithobjects( quotetoupdate, // quote object lineitemstoupdate, // list of quotelineitem objects date newinstance(2024, 5, 1) // new start date may 1, 2024 )); // execute update with object manipulation service updatestartdate(updaterequests); // after this call, your quotetoupdate and lineitemstoupdate objects // will be populated with the new calculated dates from the pricing engine system debug('quote object start date ' + quotetoupdate nue subscriptionstartdate c); system debug('quote object end date ' + quotetoupdate nue subscriptionenddate c); for (quotelineitem lineitem lineitemstoupdate) { system debug('line item ' + lineitem id + ' start date ' + lineitem nue subscriptionstartdate c); system debug('line item ' + lineitem id + ' end date ' + lineitem nue subscriptionenddate c); } benefits of this method no additional database queries after the update direct manipulation of objects already in memory useful for complex business logic that operates on the updated objects more efficient when you need to work with the updated data immediately error handling examples example 1 handling null parameters try { globalheaderobjectservice service = new globalheaderobjectservice(); // this will throw an illegalargumentexception service updatestartdate(null, date today()); } catch (illegalargumentexception e) { system debug('error ' + e getmessage()); // handle the error gracefully } example 2 handling invalid quote ids try { globalheaderobjectservice service = new globalheaderobjectservice(); // using a non existent quote id id invalidquoteid = '0q0xx0000000999'; service updatestartdate(invalidquoteid, date today()); } catch (queryexception e) { system debug('quote not found ' + e getmessage()); // handle missing quote scenario } example 3 comprehensive error handling public static void updatequotestartdatesafely(id quoteid, date newstartdate) { try { // validate inputs if (quoteid == null) { throw new illegalargumentexception('quote id cannot be null'); } if (newstartdate == null) { throw new illegalargumentexception('new start date cannot be null'); } // check if quote exists and is editable list\<quote> quotes = \[select id, nue subscriptionstartdate c, issyncing, status c from quote where id = \ quoteid limit 1]; if (quotes isempty()) { throw new illegalargumentexception('quote not found with id ' + quoteid); } quote quote = quotes\[0]; // business validation if (quote issyncing) { throw new illegalargumentexception('cannot update quote while it is syncing'); } // execute the update globalheaderobjectservice service = new globalheaderobjectservice(); service updatestartdate(quoteid, newstartdate); system debug('quote start date updated successfully from ' + quote nue subscriptionstartdate c + ' to ' + newstartdate); } catch (exception e) { system debug('failed to update quote start date ' + e getmessage()); // log error, send notification, etc throw e; // re throw if needed } } common use cases 1\ project delay handling when a project is delayed, update all related quotes to reflect new start dates // get all quotes for a specific opportunity list\<quote> quotestoupdate = \[select id from quote where opportunityid = \ opportunityid]; list\<globalheaderobjectstartdateupdate> updates = new list\<globalheaderobjectstartdateupdate>(); date delayedstartdate = date today() adddays(30); // 30 day delay for (quote q quotestoupdate) { updates add(new globalheaderobjectstartdateupdate(q id, delayedstartdate)); } new globalheaderobjectservice() updatestartdate(updates); 2\ fiscal year alignment align quote start dates to the beginning of fiscal periods date fiscalyearstart = date newinstance(2024, 4, 1); // april 1, 2024 globalheaderobjectservice service = new globalheaderobjectservice(); service updatestartdate(quoteid, fiscalyearstart); 3\ contract renewal preparation update quote start dates for contract renewals // set renewal to start when current contract ends date renewalstartdate = currentcontractenddate adddays(1); globalheaderobjectservice service = new globalheaderobjectservice(); service updatestartdate(renewalquoteid, renewalstartdate); troubleshooting common issues and solutions issue cause solution illegalargumentexception startdateupdatewitholdstartdate cannot be null null parameter passed always validate parameters before calling methods queryexception list has no rows for assignment quote id doesn't exist verify quote exists before updating rubyexception cannot find the header object with pricing engine calculation result pricing engine communication issue check org settings and try again system limitexception too many dml statements too many individual updates use bulk update methods instead debug tips enable debug logs for the globalheaderobjectservice class check quote status ensure quote is not locked or in an invalid state verify pricing engine connectivity in your org test with small datasets first before bulk operations