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

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.

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!

3 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…

Leave a 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.