Loading

How to make Opportunity and Quote Sync work when Quote creation and Opportunity update in made using Process Builder/Flows

Publiceringsdatum: Oct 13, 2022
Beskrivning

When one has a Process Builder that gets invoked when an Opportunity is created and is further calling an Autolaunched flow to pass the opportunity Id. This flow is creating a Quote with Quote.OpportunityId for the newly created Opportunity and updating the Opportunity.SyncedQuoteId to the created Quote.

In this scenario, Quote is getting created and Opportunity.SyncedQuoteId also has the Quote Id, but Quote.IsSyncing field is "False" and Quote UI shows "Start Sync" button.

On clicking "Start Sync", there is nothing to sync.

We get message: "Quote TestFromPB is already synced with this opportunity. An opportunity can be synced with only one quote. If you continue, TestFromPB won’t sync."
The quote doesn’t have any line items, and the opportunity doesn’t have any products.
After a quote is synced, opportunity products and quote line items are updated automatically.

Quote.IsSyncing is "False"

Lösning

Cause:

When Quote is created it is in unsync state and hence the Opportunity.SyncedQuoteId should be null.
 

In this case, when Opportunity Insert, Quote Insert, and Opportunity Update happen in Single Transaction, the flow action sets Opportunity.SyncedQuoteId to the created Quote Id and hence the process detects no change in the Quote Id while syncing and hence does not sync.
 

The Opportunity is saved in a parent transaction and the same transaction is not ended. In the same transaction, the Quote is inserted and the Opportunity is updated. The issue here is the Opportunity entity Insertion and the Opportunity entity save with updated SyncedQuoteId are in the same transaction. Since it is a recursive save, the sync is not triggered during the update action. The Quote Id is anyways updated on the opportunity. 
 

During the start sync process, the quote Id should be different from the SyncedQuoteId field. If it is different, the quote is synced else it is ignored.
 

If a new quote is created manually and synced, synced Quote Id differs from this and hence the sync is completed successfully.
 

As per the Document Flows in Transactions 
Flow's transaction ends when a pause element is executed.

The solution is to separate the transaction.

Create a Schedule Action as "after 0 hours of CreatedDate" in the Process Builder before calling the flow to separate the transaction.

How Does Salesforce Process Scheduled Actions?

Knowledge-artikelnummer

000391126

 
Laddar
Salesforce Help | Article