2

I have setup the necessary Account Data Integration Rules for the billing address but in a test context these values are not being populated.

I can't find any documentation on when/how the values get populated or if they're not available in test methods.

I am aware I can set this manually, but does anyone have any supported documentation that delves into this?

Test:

@IsTest
public without sharing class AccountsTest {

    @TestSetup
    static void setup() {
        Account a = new Account();
        a.RecordTypeId = [
            SELECT Id
            FROM RecordType
            WHERE SObjectType = 'Account'
                AND DeveloperName = 'Location'
        ].Id;
        a.BillingStreet = '1417 R Street';
        a.BillingCity = 'Sacramento';
        a.BillingState = 'California';
        a.BillingPostalCode = '95811';
        a.BillingGeocodeAccuracy = 'Address';
        a.Name = 'Test Location';
        insert a;
    }

    @IsTest
    static void testLocation() {
        Account a = [SELECT BillingAddress, BillingLatitude, BillingLongitude FROM Account LIMIT 1];

        System.assertNotEquals(null, a.BillingLatitude);
        System.assertNotEquals(null, a.BillingLongitude);

        Location loc = a.BillingAddress;
        System.assertNotEquals(null, loc.getLatitude());
        System.assertNotEquals(null, loc.getLongitude());
    }
}
  • I'm pretty sure that data.com runs asynchronously, and therefore wouldn't be available in a unit test. I can't seem to find documentation on it, but this seems like it couldn't work. – sfdcfox Jan 19 '18 at 22:14
0

Though not documented, the geocoding uses a third-party provider and happens asynchronously.

You should set the BillingLatitude and BillingLongitude in your test class. Make up whatever numbers you'd like.

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.