+ Start a Discussion
Brian Sherman 22Brian Sherman 22 

Test Class Fails with certain Process Builder flow active

One of my text classes is failing, but only when I have a specific process builder flow active.  Email error is:

An error occurred at element myPreWaitDecision_myWait_myRule_8 (FlowDecision).
The flow failed to access the value for myVariable_current.Site__r.Company__r.Company_Code__c because it hasn't been set or assigned.

Flow Details
Flow Name: Rental_Inquiry_Autoresponse
Type: Workflow
Version: 1
Status: Active
Flow Interview Details
Interview Label: Rental_Inquiry_Autoresponse-1_Lead_To_Site_Association__c
Current User: Brian Sherman (0051a000000uXsZ)
Start time: 26/02/2016 12:17 PM
Duration: 0 seconds
How the Interview Started
Brian Sherman (0051a000000uXsZ) started the flow interview.
Some of this flow's variables were set when the interview started.
myVariable_old = null
myVariable_current = a0355000001UEm3AAG
ASSIGNMENT: myVariable_waitStartTimeAssignment
{!myVariable_waitStartTimeVariable} Equals {!Flow.CurrentDateTime}
{!myVariable_waitStartTimeVariable} = "26/02/2016 12:17 PM"
DECISION: myPreWaitDecision_myWait_myRule_10
ASSIGNMENT: myWaitAssignment_myWait_myRule_10
{!cancelWaits} Add myWait_myRule_10
{!cancelWaits} = "[myWait_myRule_10]"

Here is the class:
private class SL_Test_EmailParser
  static void itShould()
    Suite_Type__c s = new Suite_Type__c();
    s.Name = '1 Bedroom';
    s.Synonyms__c = '1 Bedroom';

    insert s;

    Site__c site = new Site__c(Name = 'Default');
    insert site;

    Ad_Source__c a = new Ad_Source__c();
    a.Name = 'Test';
    a.Email_Domain__c = 'test.com';
    insert a;

    Eml_Parsing_Rules__c e = new Eml_Parsing_Rules__c();
    e.Synonyms__c = 'Building|Property|Ad Address';
    e.RI_Fld_API_Name__c = 'Site__c';
    e.Active_Rule__c = true;
    e.RecordTypeId = Schema.SObjectType.Eml_Parsing_Rules__c.getRecordTypeInfosByName().get('Generic Rule').getRecordTypeId();

    insert e;

    Eml_Parsing_Rules__c e2 = new Eml_Parsing_Rules__c();
    e2.Synonyms__c = 'Required Bedroom|Size|Bedrooms|Type';
    e2.RI_Fld_API_Name__c = 'Suite_Type__c';
    e2.Active_Rule__c = true;
    e2.RecordTypeId = Schema.SObjectType.Eml_Parsing_Rules__c.getRecordTypeInfosByName().get('Generic Rule').getRecordTypeId();

    insert e2;

    Eml_Parsing_Rules__c e3 = new Eml_Parsing_Rules__c();
    e3.Synonyms__c = 'Email|From|E-mail Address|Email Address';
    e3.Lead_Field_API_Name__c = 'Email';
    e3.Active_Rule__c = true;
    e3.Regex__c = '([a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+.[a-zA-Z0-9-.]+)';
    e3.RecordTypeId = Schema.SObjectType.Eml_Parsing_Rules__c.getRecordTypeInfosByName().get('Generic Rule').getRecordTypeId();

    insert e3;

    Eml_Parsing_Rules__c e4 = new Eml_Parsing_Rules__c();
    e4.RI_Fld_API_Name__c = 'Move_In_Date__c';
    e4.Active_Rule__c = true;
    e4.Domain__c = 'test.com';
    e4.DS_Regex__c = '(\\d{1,2})-(\\w{1,3})-(\\d{4})';
    e4.Date_Regex__c = '(\\d{1,2})-(\\w{1,3})-(\\d{4})';
    e4.Year_Group__c = '3';
    e4.Month_Group__c = '2';
    e4.Day_Group__c = '1';
    e4.RecordTypeId = Schema.SObjectType.Eml_Parsing_Rules__c.getRecordTypeInfosByName().get('Domain Specific Rule').getRecordTypeId();

    insert e4;

    Site__c s2 = new Site__c(Name='Test Site2');
    s2.GeoLocation__latitude__s = 000.000001;
    s2.GeoLocation__longitude__s = 000.000001;
    insert s2;

    Building__c b = new Building__c(Name = 'Test', Site__c=s2.Id);
    insert b;

    Id [] fixedSearchResults= new Id[1];
    fixedSearchResults[0] = s2.Id;

    Messaging.inboundEmail eml = new Messaging.inboundEmail();
    eml.fromAddress = 'test@test.com';
    eml.plainTextBody = 'Property-Test Site2\nType-1 Bedroom\nEmail-testname@testname.com\n02-Jan-2015';
    eml.toAddresses = new String[]{'test2@test2.com'};
    eml.fromName = 'Test Name';

    Messaging.InboundEnvelope env = new Messaging.InboundEnvelope();
    env.fromAddress = 'test@test.com';
    env.toAddress = 'test2@test2.com';

    SL_EmailParser emp = new SL_EmailParser();


Any ideas?  If I disable a process builder flow the test passes.