{"id":840,"date":"2021-04-07T12:36:00","date_gmt":"2021-04-07T12:36:00","guid":{"rendered":"http:\/\/morecpq.com\/?p=840"},"modified":"2023-09-12T16:11:16","modified_gmt":"2023-09-12T20:11:16","slug":"cpq-auto-generate-contract-and-auto-generate-renewal-opportunity-and-renewal-quote-on-contract","status":"publish","type":"post","link":"https:\/\/morecpq.com\/index.php\/2021\/04\/07\/cpq-auto-generate-contract-and-auto-generate-renewal-opportunity-and-renewal-quote-on-contract\/","title":{"rendered":"CPQ &#8211; Auto generate Contract and auto generate Renewal Opportunity and Renewal Quote on Contract."},"content":{"rendered":"\n<p>Salesforce Support&#8217;s official stance is to NOT use Workflow Rules OR Process Builder OR Scheduled Flows for Renewal Forecast, Renewal Quoted or Contracting. This is because Contracts will mysteriously not always generate if you do this.  The same thing can happen with renewal quotes not being created. The recommendation is to move your automation to batch APEX.  WHAAAAT?!  Salesforce is recommending writing code instead of only clicks???  Code, not CLICKS?!?!  Up is DOWN!  Left is RIGHT!  THE WORLD IS ENDING!  Not exactly.<\/p>\n\n\n\n<p>In the past, I have always created process builders to auto check these checkbox fields.  The problem with this is that you can hit limits if you add too much of your OWN automation around the CPQ automation, especially if you want to do things in bulk like, for example, close win a batch of 1000 Opps.  This can hit the <a rel=\"noreferrer noopener\" href=\"https:\/\/lanefour.com\/2020\/05\/22\/apex-cpu-time-limit-exceeded\/#:~:text=Salesforce%20limits%20CPU%20usage%20to,and%20can't%20be%20completed.\" target=\"_blank\">APEX CPU Time Limit<\/a> and\/or the <a rel=\"noreferrer noopener\" href=\"https:\/\/developer.salesforce.com\/docs\/atlas.en-us.salesforce_app_limits_cheatsheet.meta\/salesforce_app_limits_cheatsheet\/salesforce_app_limits_platform_apexgov.htm\" target=\"_blank\">Max Queries Limit<\/a>.  Another detail is how Salesforce executes scheduled actions.  The system will combine all actions based on a Date field, that happen on a given day, together into one transaction.  So if you update 1000 Opps to closed won, then 1000 Opps will get scheduled to Contract at the same time (and then those 1000 Contracts will get scheduled to Renew at the same time), and you&#8217;ll be neck deep in limit errors.<\/p>\n\n\n\n<p>Also, a weird thing can happen where, if you string the Contracted checkbox and the Renewal checkboxes together, the Contracted field update combined with the Renewal field updates will renew the Contract before Subscriptions are created (while the Opp is being Contracted), resulting in Renewal Opportunities without renewed Opportunity Products. Article <a rel=\"noreferrer noopener\" href=\"https:\/\/help.salesforce.com\/articleView?id=000312893&amp;type=1&amp;mode=1\" target=\"_blank\">here<\/a>.<\/p>\n\n\n\n<p>While analyzing this, I figured a possible solution so that you don&#8217;t have to write APEX code.  First, put everything into a Scheduled Action inside of a Flow.  The caveat: do not base it on just a Date field.  Instead, base it on a Date\/Time field.  This way, Salesforce can not bulk up these transactions into one because they are based on a time with milliseconds.  Below find some generic screenshots of examples of this.  (FYI: If you REALLY wanna do APEX: go <a rel=\"noreferrer noopener\" href=\"https:\/\/help.salesforce.com\/articleView?id=000318647&amp;type=1&amp;mode=1&amp;language=en_US\" target=\"_blank\">here<\/a>.)<\/p>\n\n\n\n<p><strong>Opportunity<\/strong><br>On Update, if Stage is changed to Closed Won, schedule an action to happen zero hours after the CreatedDate (Date\/Time) field to check the Contracted checkbox.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img data-recalc-dims=\"1\" decoding=\"async\" width=\"538\" height=\"565\" src=\"https:\/\/i0.wp.com\/morecpq.com\/wp-content\/uploads\/2021\/08\/image-5.png?resize=538%2C565&#038;ssl=1\" alt=\"\" class=\"wp-image-1139\" srcset=\"https:\/\/i0.wp.com\/morecpq.com\/wp-content\/uploads\/2021\/08\/image-5.png?w=538&amp;ssl=1 538w, https:\/\/i0.wp.com\/morecpq.com\/wp-content\/uploads\/2021\/08\/image-5.png?resize=286%2C300&amp;ssl=1 286w\" sizes=\"(max-width: 538px) 100vw, 538px\" \/><\/figure>\n\n\n\n<p><strong>Order<\/strong><br>Contracting against the Opportunity is one way to Contract!  You can also Contract against the Order.  Here&#8217;s the flow for that!  On Order activation, Contract the Order.  You can also have automation generate the order from the Primary Quote.  Let us know if you&#8217;d like to see that flow!<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img data-recalc-dims=\"1\" decoding=\"async\" width=\"683\" height=\"710\" src=\"https:\/\/i0.wp.com\/morecpq.com\/wp-content\/uploads\/2023\/09\/image.png?resize=683%2C710&#038;ssl=1\" alt=\"\" class=\"wp-image-2505\"\/><\/figure>\n\n\n\n<p><strong>Contract<\/strong><br>On Create, if Status = Activated, immediately update a Contract End Date\/Time field to be a Date\/Time version of the End Date field, schedule an action 1 hour after CreatedDate (Date\/Time) field to create the Renewal Opp, and schedule another action 30 days before the Contract End Date\/Time field to create the Renewal Quote.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img data-recalc-dims=\"1\" decoding=\"async\" width=\"801\" height=\"546\" src=\"https:\/\/i0.wp.com\/morecpq.com\/wp-content\/uploads\/2021\/08\/image-6.png?resize=801%2C546&#038;ssl=1\" alt=\"\" class=\"wp-image-1140\" srcset=\"https:\/\/i0.wp.com\/morecpq.com\/wp-content\/uploads\/2021\/08\/image-6.png?w=801&amp;ssl=1 801w, https:\/\/i0.wp.com\/morecpq.com\/wp-content\/uploads\/2021\/08\/image-6.png?resize=300%2C204&amp;ssl=1 300w, https:\/\/i0.wp.com\/morecpq.com\/wp-content\/uploads\/2021\/08\/image-6.png?resize=768%2C524&amp;ssl=1 768w\" sizes=\"(max-width: 801px) 100vw, 801px\" \/><\/figure>\n\n\n\n<p>This is a short one but you&#8217;ve reached the end!  You get a cookie!  Below are some install links for all the things above!  <\/p>\n\n\n\n<p><a rel=\"noreferrer noopener\" href=\"https:\/\/login.salesforce.com\/packaging\/installPackage.apexp?p0=04t4x000000lwkO\" target=\"_blank\">Production<\/a> : <a rel=\"noreferrer noopener\" href=\"https:\/\/test.salesforce.com\/packaging\/installPackage.apexp?p0=04t4x000000lwkO\" target=\"_blank\">Sandbox<\/a><\/p>\n\n\n\n<p>Feel free to update the processes to your own needs after install!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Salesforce Support&#8217;s official stance is to NOT use Workflow Rules OR Process Builder OR Scheduled Flows for Renewal Forecast, Renewal Quoted or Contracting. This is because Contracts will mysteriously not always generate if you do this. The same thing can happen with renewal quotes not being created. The recommendation is to move your automation to &hellip;<br \/><a href=\"https:\/\/morecpq.com\/index.php\/2021\/04\/07\/cpq-auto-generate-contract-and-auto-generate-renewal-opportunity-and-renewal-quote-on-contract\/\" class=\"more-link pen_button pen_element_default pen_icon_arrow_double\">Continue reading <span class=\"screen-reader-text\">CPQ &#8211; Auto generate Contract and auto generate Renewal Opportunity and Renewal Quote on Contract.<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-840","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"jetpack_featured_media_url":"","jetpack-related-posts":[],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/morecpq.com\/index.php\/wp-json\/wp\/v2\/posts\/840","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/morecpq.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/morecpq.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/morecpq.com\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/morecpq.com\/index.php\/wp-json\/wp\/v2\/comments?post=840"}],"version-history":[{"count":17,"href":"https:\/\/morecpq.com\/index.php\/wp-json\/wp\/v2\/posts\/840\/revisions"}],"predecessor-version":[{"id":2508,"href":"https:\/\/morecpq.com\/index.php\/wp-json\/wp\/v2\/posts\/840\/revisions\/2508"}],"wp:attachment":[{"href":"https:\/\/morecpq.com\/index.php\/wp-json\/wp\/v2\/media?parent=840"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/morecpq.com\/index.php\/wp-json\/wp\/v2\/categories?post=840"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/morecpq.com\/index.php\/wp-json\/wp\/v2\/tags?post=840"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}