0

I am attempting to utilize Financial Services Cloud in Salesforce. One of the interesting quirks about it is that an Account insertion is immediately followed by a Contact insertion and both records share the same FinServ__IndividualId__c.

I am attempting to write a test class that requires testing this relationship, but I'm unable to insert a Contact record of type "Individual" and have a contact created through the managed package trigger and associated individual Ids. In fact, none of that happens. I just have an inserted account.

I have a commented-out section and that was another approach.

The result is Account:{Name=234, Id=0013D00000OAwXNQA1, FinServ__IndividualType__c=Individual, RecordTypeId=0126A0000008xahQAA}

Account a = new Account();
    Contact c = new Contact();
    c.LastName='fname?';
    c.FirstName='lname';
    insert c;
    //a.RecordTypeId = [SELECT DeveloperName, Id, SobjectType 
                      //FROM RecordType 
                      //Where SobjectType='Account' 
                      //AND DeveloperName='IndustriesIndividual'][0].Id;
    a.RecordTypeId=Schema.SObjectType.Account.getRecordTypeInfosByName().get('Individual').getRecordTypeId();
    a.Name='234';
    a.FinServ__IndividualType__c ='Individual';
    a.FinServ__PrimaryContact__c=c.Id;
    insert a;
    a=[Select Name, Id, FinServ__IndividualId__c, FinServ__IndividualType__c, RecordType.DeveloperName FROM Account Where Id=:a.Id];
    System.debug(a.RecordType.DeveloperName);
    System.debug(a);

Does anybody have any experience/suggestions with this?

I have attempted the following example: https://success.salesforce.com/issues_view?id=a1p3A000000mCmQQAU --with no success, including attempting the suggested work-arround.

  • 1
    why isn't your testmethod just inserting the Account and verifying that both Account+Contact are inserted? I'll admit I know nothing about FS Cloud – cropredy Dec 2 '17 at 5:46
  • Admittedly, there's a bit extra in there. The Client object shouldn't need to be defined at all, since inserting an account properly should create a Contact object, as well. The important part is: Account a = new Account(); set some account stuff insert a; System.debug(a); At that point, it should have a FinServ_Individual_Id__c filled with numbers. – Caleb Kuester Dec 4 '17 at 16:24
  • 1
    you might want to edit the question to focus on this fundamental issue. Is it possible you need to do the query on Account in the testmethod after a Test.stopTest() statement as perhaps FS does its work asynchronously and those methods don't run until test.stopTest ? – cropredy Dec 4 '17 at 18:06
  • @cropredy I wouldn't mind that in the form of an answer so that I can vote it "best." "asynchronous" was the solution! – Caleb Kuester Dec 5 '17 at 22:11
  • glad this was the answer – cropredy Dec 5 '17 at 22:58
1

It would appear by experimentation of @calebKuester that Financial Services Cloud assigns the value Account.FinServ__IndividualId__c in an asynchronous operation.

As such, the Test class should be modified to look like:

....
Test.startTest();
insert a;
Test.stopTest(); // runs FS Cloud async methods
a=[Select Name, Id, FinServ__IndividualId__c, FinServ__IndividualType__c,
          RecordType.DeveloperName FROM Account Where Id=:a.Id];
System.assertNotEquals(null,a.FinServ__IndividualId__c,'FS IndiviualID sb assigned when Account is inserted');
.. more asserts
  • In addition, @future markup should be applied to a separate method created for the purpose of entering the record in question. The method must be called within the start/stopTest() – Caleb Kuester Dec 6 '17 at 17:20
  • then I might not fully understand the root cause - I thought merely inserting an Account in FS Cloud caused the issue - why is a future method in the code-under-test required? – cropredy Dec 6 '17 at 17:29
1

cropredy pointed me in the right direction.

Solution is mostly here: https://developer.salesforce.com/forums/?id=906F00000008wViIAI

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.