CPQ – Auto generate Contract and auto generate Renewal Opportunity and Renewal Quote on Contract.

Salesforce Support’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.

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 APEX CPU Time Limit and/or the Max Queries Limit. 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’ll be neck deep in limit errors.

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 here.

While analyzing this, I figured a possible solution so that you don’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 here.)

Opportunity
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.

Order
Contracting against the Opportunity is one way to Contract! You can also Contract against the Order. Here’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’d like to see that flow!

Contract
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.

This is a short one but you’ve reached the end! You get a cookie! Below are some install links for all the things above!

Production : Sandbox

Feel free to update the processes to your own needs after install!

7 thoughts on “CPQ – Auto generate Contract and auto generate Renewal Opportunity and Renewal Quote on Contract.

  1. Hello DP,
    Keep up with the awesome work!
    In this article you have covered generating Contract from Opportunity.
    What if we generate and Order from Opportunity using Process Builder? And also generate a Contract from Order using Process Builder once the Order is activated?
    Thank you!

    1. This is quite a great point Nitin! I’ll be updating this article with a revised solution to include Contracting from Order! Stay tuned…

  2. Great work Dennis. We’re running into this issue, even after scheduling out the renewal forecast and renewal quotes. We get an exclusive access error. This doesn’t happen on every contract, but its happening quote often.. Maybe related to other opportunity flows we have (ex. one flow adds default values upon creation)…but we don’t see this in debug logs when looking at the DML statements. Have you seen this issue before? Could other flows be causing this conflict?

    1. Hi Drew! I have seen exclusive access issues before. Usually this is because of other automation. For example: You have a flow for after a quote is saved, loop through lines and update a field. This will try to update lines that have already been grabbed by CPQ to run a calculate sequence, in some scenarios. Like creating a renewal or amendment.

Leave a Reply to Nitin Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.