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 45 forks source link

Synchronization job workflow fails when matching existing service cloud records on email without a customer List #137

Open nek4life opened 2 years ago

nek4life commented 2 years ago

Describe the bug When running the synchronization job with existing records in service account that match up to existing records in commerce cloud the work flow fails with the following error.

Error element ia_validateIntegrationConfiguration (FlowActionCall).
An Apex error occurred: System.NullPointerException: Attempt to de-reference a null object 

Flow Details
Flow API Name: B2CCommerce_PlatformEvent_ProcessContactUpdate
Type: Autolaunched Flow
Version: 1
Status: Active

Flow Interview Details
Interview Label: B2C Commerce: Platform Event: Process Contact: 3/4/2022, 11:29 AM
Start time: 3/4/2022, 11:29 AM
Duration: 0 seconds

How the Interview Started
API Version for Running the Flow: 52
Some of this flow's variables were set when the interview started.
$Record = B2C_Commerce_ProcessCustomerDetails__e (No ID)

DECISION: Is ProcessMode Valid
Skipped this outcome because its conditions weren't met: decOutcome_ProcessModeIsInValid
Outcome conditions: 
1. {!$Record.Process_Mode__c} (retrieve) Does not equal retrieve
2. {!$Record.Process_Mode__c} (retrieve) Does not equal publish
Logic: All conditions must be true (AND)

Default outcome executed.

GET RECORDS: Get the Contact Record
Find all Contact records where:
Id Equals {!$Record.CRM_Contact_ID__c} (0030500000NPTq3AAH)
Store the values of these currently referenced fields in recGet_Contact: AccountId, Id
Because recGet_Contact is passed to an action, subflow, or Lightning component, store the values of all Contact fields that the running user has access to.
Result
Successfully found records.

DECISION: Was the Contact Found?
Outcome executed: decOut_ContactWasVerfiied
Outcome conditions: 
{!$Record.CRM_Contact_ID__c} (0030500000NPTq3AAH) Equals {!recGet_Contact.Id} (0030500000NPTq3AAH)

DECISION: Does the Contact Have a Parent Account?
Skipped this outcome because its conditions weren't met: decOut_ContactDoesNotHaveParentAccount
Outcome conditions: 
{!recGet_Contact.Account.Id} (0010500000PlvbpAAB) Equals true

Default outcome executed.

GET RECORDS: Get the B2C CustomerList
Find all B2C_CustomerList__c records where:
Id Equals {!$Record.CRM_CustomerList_ID__c} (null)
Store the values of these currently referenced fields in recGet_B2CCustomerList: B2C_Client_ID_Value__c, Audit_OCAPI_API_Response__c, Base_API_Url__c, JWT_Certificate_Name__c, Id, B2C_Instance__c, B2C_Client_ID__c
Because recGet_B2CCustomerList is passed to an action, subflow, or Lightning component, store the values of all B2C_CustomerList__c fields that the running user has access to.
Result
Failed to find records.

GET RECORDS: Get the Related B2C Instance
Find all B2C_Instance__c records where:
Id Equals {!recGet_B2CCustomerList.B2C_Instance__c} (null)
Store the values of these currently referenced fields in recGet_B2CInstance: Id
Because recGet_B2CInstance is passed to an action, subflow, or Lightning component, store the values of all B2C_Instance__c fields that the running user has access to.
Result
Failed to find records.

B2CIAVALIDATECONTACT (APEX): Validate Integration Configuration
Inputs:
b2cInstance = {!recGet_B2CInstance} (null)
contact = {!recGet_Contact} (Contact (0030500000NPTq3AAH))
customerList = {!recGet_B2CCustomerList} (null)
processMode = {!$Record.Process_Mode__c} (retrieve)

Error Occurred: An Apex error occurred: System.NullPointerException: Attempt to de-reference a null object 

To Reproduce Steps to reproduce the behavior:

  1. Load accounts into Service Cloud
  2. Create customers in Commerce cloud with the same email address
  3. Run synchronization job provided by b2-crm-sync
  4. Observe workflow error

Expected behavior Account should be matched and updated with the current customer list, customer no and customer id in order for account to be properly synchronized. This job is needed when establishing connector with existing commerce cloud and service cloud instances

nek4life commented 2 years ago

I'm able to replicate this without the job directly in the flow in service cloud

Screen Shot 2022-03-07 at 5 07 35 PM

Customer list should be valid. First name, last name, email should match newly recreated record. Customer No and Customer ID need to be filled in to similar values that would be sent by the process contact job in SFCC

jbachelet commented 2 years ago

Hello @nek4life,

Thank you for posting this issue. That's actually the expected behavior, as the person account you are creating initially has no customer list value, so crm-sync is not able to find a match as this value is a hardly-required value here.

Can you please try to put a value in the customer list field when inserting person accounts in Core, and then either run the flow or the job?

Thanks

nek4life commented 2 years ago

Hi @jbachelet thanks for the update!

The problem is that a customer is matched, but fails further down in the flow even though when sending the flow request with the customer list ID from commerce.

Here's an example. A customer signs up through a channel that is not commerce cloud. This customer does not have a customer list assigned at this time.

The same customer signs up for an account or is synced through the sync job. The sync request to the flow includes the customer list and a customer is matched. Even though the flow has match the customer and the incoming request has the customer list ID sent in with the request this flow throws the above error.

Expected result would be that the customer is matched and the customer list is assigned based on the incoming request.

Hopefully this additional detail explains the problem a bit better.

jbachelet commented 2 years ago

Hello @nek4life ,

Thank you for this well-detailed context, it totally makes sense to me now. Apologize if I did not get it the first time. I'll look into this and improve this piece of the crm-sync core matching logic to ensure this use case is covered.

Will let you know.

nek4life commented 2 years ago

Thanks @jbachelet! Slightly related, it does seem a bit odd that a customer list ID is expected even with guest checkout as that customer may or may not actually be a registered customer and not be assigned to an actual customer list.

Since there isn't any support for syncing ad-hoc forms at this time we looked at how guest checkouts worked since they are a similar use case and were able to reuse the flow, however we still need to send a customer list in for this as well. Ideally the request wouldn't require a customer list because that customer for either ad-hoc form like an email signup or guest checkout really shouldn't be assigned to a customer list.

Perhaps this is a larger architectural issue related to how the api connection details are stored within the framework. For this issue I don't expect this to be resolved, but wanted to mention as others may be facing the same issue or questions about their implementation.

ranveer5289 commented 2 years ago

@jbachelet : We are also facing a similar issue. In our case, the client has SF OMS enabled and OMS creates a person account when a new order is created in the system and no existing person account exists yet in SF. Now, if the same customer tries to create an account in SFCC at a later stage, we get the same error as in the issue description.