SalesforceCommerceCloud / b2c-crm-sync

... a contemporary perspective on how to integrate B2C Commerce and the Salesforce Customer 360 Platform to power frictionless customer experiences in the B2C domain.
https://salesforcecommercecloud.github.io/b2c-crm-sync/
BSD 3-Clause "New" or "Revised" License
65 stars 46 forks source link

[BUG] 100+ Callout Problem in Core Flow - B2C Commerce: Platform Event: Process Contact Update #275

Open sandrolu opened 3 months ago

sandrolu commented 3 months ago

First problem: Multiple auth calls In B2CIARequestB2CAuthToken when it is invoked by the flow B2C Commerce: Platform Event: Process Contact Update

The first BULK update of accounts containing more than 100 accounts will fail, this is because in the trigger account you publish an event with a collection of 100+ accounts, then in the flow, if you don't have the B2C Token, you call the invokable to make the HTTP callout image

Here is the error, you are cycling through N accounts, you are not cycling through unique B2C Id, but you are cycling through N accounts, this is how flow works. image

and here is the error image

For projects that has only 1 B2C client in our case, since we can't spend much time, we just applied a quick fix by moving the http.send request outside of the loop, since all the accounts will have the same B2C Client and JWT.

But for a more solid package, you may want to make an additional loop by getting a map of unique b2c Id and make X requests.

Second problem: Max calls 101 callouts when trigger on account is calling B2CProcessPersonAccountHelper.processTrigger(Trigger.new, Trigger.old); image

it will trigger the flow B2CCommerce_PlatformEvent_ProcessContactUpdate, which will contain more than 100 accounts and it will then invoke B2C: Publish Customer Profile Definitions or B2C: Get Customer Profile and will make more than 100 callouts.

I have created a Queueable solution to limit to 80 accounts so it will not go over the limit of callouts - this is just a temporary solution, please consider this solution and try to fix it into a more scalable solution rather than using flow and blocking org limit. This problem may not exist if in lower versions of flows salesforce have a lower bulk size grouping in the core.

image image

Best, Sandro Lu Senior Salesforce Architect