2

I'm using the Android SDK, Chat functionalities, currently I'm able to create a new Contact, Case and link those two. How can I link the created Contact/Case to an existing account?

The following code is capable to create a new Case, but it is not making the link with the Account.

// Account 
val accountEntity = ChatEntity.Builder()
                .showOnCreate(true)
                .linkToTranscriptField("Account")
                .addChatEntityField(
                        ChatEntityField.Builder()
                                .doFind(true)
                                .isExactMatch(true)
                                .doCreate(false)
                                .build("AccountNumber", erpCustomerNumber))
                .build("Account")

// Map Subject to a field in a Case record
val caseEntity = ChatEntity.Builder()
                .showOnCreate(true)
                .linkToTranscriptField("Case")
                .linkToAnotherSalesforceObject(accountEntity, "AccountId")
                .addChatEntityField(
                        ChatEntityField.Builder()
                                .doFind(true)
                                .isExactMatch(true)
                                .doCreate(true)
                                .build("Subject", subject))
                .build("Case")

The following code is capable to link the Contact with the Case:

val contactEntity = ChatEntity.Builder()
                .showOnCreate(true)
                .linkToTranscriptField("Contact")
                .linkToAnotherSalesforceObject(caseEntity, "ContactId")
                .addChatEntityField(firstNameField)
                .addChatEntityField(lastNameField)
                .addChatEntityField(emailField)
                .addChatEntityField(descriptionField)
                .build("Contact")
1

Based on the documentation, the linkToAnotherSalesforceObject method is to be invoked by the pointed entity in the lookup relationship (just like you have done in your Contact working example).

So you may try declaring the caseEntity first and then referencing it in the Account ChatEntity instantiation:

// Map Subject to a field in a Case record
val caseEntity = ChatEntity.Builder()
                .showOnCreate(true)
                .linkToTranscriptField("Case")
                .addChatEntityField(
                        ChatEntityField.Builder()
                                .doFind(true)
                                .isExactMatch(true)
                                .doCreate(true)
                                .build("Subject", subject))
                .build("Case")
// Account 
val accountEntity = ChatEntity.Builder()
                .showOnCreate(true)
                .linkToTranscriptField("Account")
                .linkToAnotherSalesforceObject(caseEntity, "AccountId")
                .addChatEntityField(
                        ChatEntityField.Builder()
                                .doFind(true)
                                .isExactMatch(true)
                                .doCreate(false)
                                .build("AccountNumber", erpCustomerNumber))
                .build("Account")
  • That is a good point, already try that but from Account to the Contact entity. Didn't work neither. – skimos Apr 20 '20 at 17:18
  • code .linkToAnotherSalesforceObject(contactEntity, "AccountId") code – skimos Apr 20 '20 at 17:20
0

Got the code to work. I had to link the Account to the contact instead to the case. Thanks for the help.

 // Conatct creatation
    val contactEntity = ChatEntity.Builder()
            .showOnCreate(true)
            .linkToTranscriptField("Contact")
            .linkToAnotherSalesforceObject(caseEntity, "ContactId")
            .addChatEntityField(firstNameField)
            .addChatEntityField(lastNameField)
            .addChatEntityField(emailField)
            .addChatEntityField(descriptionField)
            .build("Contact")

    // Load account
    val accountEntity = ChatEntity.Builder()
            .showOnCreate(true)
            .linkToTranscriptField("Account")
            .linkToAnotherSalesforceObject(contactEntity, "AccountId")
            .addChatEntityField(
                    ChatEntityField.Builder()
                            .doFind(true)
                            .isExactMatch(true)
                            .doCreate(true)
                            .build("AccountNumber", erpCustomerNumber))
            .build("Account")



chatConfigurationBuilder.chatUserData(firstName, lastName, email, subject, description, erpCustomerNumber)
        chatConfigurationBuilder.chatEntities(contactEntity, caseEntity, accountEntity)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.