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
64 stars 47 forks source link

I got error by email every time I update Contact. #86

Closed syunyama closed 2 years ago

syunyama commented 2 years ago

Describe the bug I am setting up following this document I got error below by email every time I update Contact.

Title:
フロー「B2C Commerce: Platform Event: Process Contact Update」でエラーが発生しました: An Apex error occurred: System.DmlEx...

Body:
エラー要素 ia_persistAndAuditB2CAuthToken (FlowActionCall)。
An Apex error occurred: System.DmlException: Insert failed. First exception on row 0; first error: STRING_TOO_LONG, B2C AuthToken: データ値が大きすぎる: eyJ0eXAiOiJK....omit.....8uB0YYwJqg (max length=80): [Name]

To Reproduce

  1. Update Contact from lightning UI.

Expected behavior No error email.

Your local environment details:

Your remote environment details:

syunyama commented 2 years ago

It seems B2C_AuthToken__c.Name is used to store access token which usually have 255 length. https://github.com/SalesforceCommerceCloud/b2c-crm-sync/blob/186302e8b15c537b2330b8923736c5e8d2ed4134/src/sfdc/base/main/default/classes/B2CIAPersistB2CAuthToken_Test.cls#L74

And default length of Text type seems to be 80. So maybe adding this <length>255</length> to around this line solve problem? https://github.com/SalesforceCommerceCloud/b2c-crm-sync/blob/186302e8b15c537b2330b8923736c5e8d2ed4134/src/sfdc/base/main/default/objects/B2C_AuthToken__c/B2C_AuthToken__c.object-meta.xml#L168

And also better to change test case to 255 length string: https://github.com/SalesforceCommerceCloud/b2c-crm-sync/blob/186302e8b15c537b2330b8923736c5e8d2ed4134/src/sfdc/base/main/default/classes/B2CIAPersistB2CAuthToken_Test.cls#L52

jbachelet commented 2 years ago

Hello @syunyama ,

Thanks for posting this. It seems you did not configure your B2C API Client correctly. You should configure it with Access Token Format: UUID, as explained in the readme here, and not leave the default JWT value.

Your case is that the access token delivered by the Account Manager is a JWT, which is more than 80 characters long. Using a UUID, the access token length will be less than 80, and the error will go away.

Please let me know if this solves the issue.

syunyama commented 2 years ago

@jbachelet Thank you for your quick reply and sorry for my misunderstanding. I confirmed it ran successfully after change to UUID.