function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
KevinRussellKevinRussell 

Trigger Test has no code coverage, how to cover code?

So, new at this..... Having said that...

I wrote a trigger that sets a Contact field checkbox to True.  I created a test for the trigger and the test ran but there is no code coverage.  What am I doing wrong, how do I connect my trigger test to my real trigger to get coverage?

 

Thanks!

 

Here is my trigger:

// Update Contact field: "Guest_Speaker__c" to TRUE when a new Interaction__c record is inserted or updated. 
// Interaction__c is not a directly related child object of Contact.
trigger Contacts_Guest_Speaker_Checkbox on Interaction__c (after insert, after update) {

// Will store Contact record ID
map< id, contact > contacts = new map< id, contact >();

// Create trigger for new or selected Interaction__c record
for(Interaction__c record:trigger.new)        

if(record.Selected_Sub_type__c == 'Speaker')

     // Update checkbox field on the Contact record to TRUE
     contacts.put(record.contact__c, new contact(id=record.contact__c, Guest_Speaker__C = TRUE));      

update contacts.values(); 

}

 

Here is my attempt at writing a test.  The test does compile, run and passes but it has no code coverage.

@isTest
private class Contacts_Guest_Speaker_CheckboxTest
{
    //set condition for True statement.
    static TestMethod void Test0_StatementTrue()
    {  
        string test0Value = 'Speaker';      
        updateCheckBox(test0Value);       
    }

    //set condition for False statement.    
    static TestMethod void Test1_StatementFalse()
    {
        string test1Value = 'Instructor';       
        updateCheckBox(test1Value);       
    }

    //set checkbox to True if value is 'Speaker', False otherwise.
    private static void updateCheckBox(String inputString)
     {
         contact con = new contact();
         con.Id = '003J000000O2KR0';         
         if (inputstring == 'Speaker')
            { 
                 con.Guest_Speaker__C = True;
            } else {
                 con.Guest_Speaker__C = False;
                    }                                         
         update con;
    }
}

 Results:

Apex Test Result Detail 

Time Started 3/26/2013 10:40 AM 
Class Contacts_Guest_Speaker_CheckboxTest 
Method Name Test1_StatementFalse 
Pass/Fail Pass 
Error Message   
Stack Trace  

 Code Coverage:

Code Coverage 

Contacts_Guest_Speaker_Checkbox (Code Covered: 0%)

 line  source 
 1   // Update Contact field: "Guest_Speaker__c" to TRUE when a new Interaction__c record is inserted or updated.  
 2   // Interaction__c is not a directly related child object of Contact. 
 3   trigger Contacts_Guest_Speaker_Checkbox on Interaction__c (after insert, after update) { 
 4    
 5   // Will store Contact record ID 
 6   map< id, contact > contacts = new map< id, contact >(); 
 7    
 8   // Create trigger for new or selected Interaction__c record 
 9   for(Interaction__c record:trigger.new)         
 10    
 11   if(record.Selected_Sub_type__c == 'Speaker') 
 12    
 13        // Update checkbox field on the Contact record to TRUE 
 14        contacts.put(record.contact__c, new contact(id=record.contact__c, Guest_Speaker__C = TRUE));       
 15    
 16   update contacts.values();  
 17    
 18   } 

 

Best Answer chosen by Admin (Salesforce Developers) 
KevinRussellKevinRussell

Hi NaiduPothini and sfdcfox,

 

Thank you both very, very,very much!

 

The test for this trigger finally passed.  I have a lot to learn....

 

Here is the test code as it is now, before I tweak anything else:

@isTest
private class Contacts_Guest_Speaker_CheckboxTest
{
    public static String rectypeId1 = [SELECT Id, Name FROM RecordType WHERE Name = 'CDC_Interaction' AND SObjectType = 'Interaction__c'].Id;
    public static String rectypeId2 = [SELECT Id, Name FROM RecordType WHERE Name = 'Alumn Interaction' AND SObjectType = 'Interaction__c'].Id;
    public static String rectypeId3 = [SELECT Id, Name FROM RecordType WHERE Name = 'ExecEd Interaction' AND SObjectType = 'Interaction__c'].Id;    

    static TestMethod void Test0_StatementTrue()
    {  
        Account acc = new Account(Name='TestAccount');
        insert acc;

        Contact con = new Contact(AccountId = acc.Id, lastName = 'TestLastName');
        insert con;

        List<Interaction__c> intList = new List<Interaction__c>();

        Interaction__c intr1 = new Interaction__c(Account__c = acc.Id, Contact__c = con.Id, RecordTypeId = recTypeId1);
        Interaction__c intr2 = new Interaction__c(Account__c = acc.Id, Contact__c = con.Id, RecordTypeId = recTypeId2);
        Interaction__c intr3 = new Interaction__c(Account__c = acc.Id, Contact__c = con.Id, RecordTypeId = recTypeId3);        

        intList.add(intr1);
        intList.add(intr2);
        intList.add(intr3);        

        insert intList;
    }
}

 

All Answers

sfdcfoxsfdcfox
You never actually triggered the trigger; you need to insert an Interaction__c record. As a side note, don't hardcode a contact ID. You should make your data "from scratch" so that it will be portable across organizations, even if you never plan to migrate it. It will future-proof your code.
KevinRussellKevinRussell

Thanks sfdcfox,

 

I'm refactoring my trigger test. 

I'm trying to write a new Interaction record to cause the trigger to fire, but I can't get it to compile:

"Error: Compile Error: Field is not writeable: Interaction__c.Interaction_Type__c at line 20 column 9"

 

The fields in question are selectable picklist values. 

  • The field Interaction_Type__C is a data type of Formula: $RecordType.Name
  • The field SubType is a Picklist
    Both of these fields are required so I need to populate them to insert a new Interaction record.

How do I set the values for those fields?

(Account and Contact IDs, I'll figure how to code these after I get the test working)

 

Here is what I've written so far. 

@isTest
private class Contacts_Guest_Speaker_CheckboxTest
{
    //set condition for True statement.
    static TestMethod void Test0_StatementTrue()
    {  
        string testContact = '003J000000O2KR0';      
        string testAccount = '001J000000TTvSv';        
        string testType = 'CDC_Interaction';
        string testSubType = 'Speaker';
        string testInteractionName = 'Guest Speaker';      
        insertInteraction(testContact, testAccount, testType,testSubType);
    }


    //set checkbox to True if value is 'Speaker', False otherwise.
    private static void insertInteraction(string AccountID, string ContactID, string Type, string subType)
     {
        interaction__c I = new Interaction__c();        
        I.Interaction_Type__c = Type;
        I.Selected_Sub_type__c = subtype;        
        I.account__c = accountID;
        I.contact__c = ContactID;       
        update I;
    }
}

 

sfdcfoxsfdcfox

Interaction_Type__c can't be required if it's a formula; don't worry, the system will calculate it for you. Subtype, however, needs to have a value. Also note, if there's no ID, you need to use insert or upsert, not update (because it doesn't exist in the database).

KevinRussellKevinRussell
Interaction_Type__c is listed as a Interaction field formula, but it's an interaction object Record Type, We select the Type as one of: CDC_Interaction, Alumn_Interaction, or ExecED through a pick list then continue to fill out the form which displays the Sub-Type picklist, a subset of the pre-selected Type. So, its required in so much as it directs us to make the Record Type choice. So, I need a way to feed the record type field value to the Interaction__C record. Do you see what I mean?
Naidu PothiniNaidu Pothini
@isTest
private class Contacts_Guest_Speaker_CheckboxTest
{
    static TestMethod void Test0_StatementTrue()
    {  
        Account acc = new Account(Name='TestAccount', ---add required fields here----);
        insert acc;

        Contact con = new Contact(AccountId = acc.Id, ---add required fields here----);
        insert con;

        Interaction__c intr = new Interaction__c(Account__c = acc.Id, Contact__c = con.Id, Selected_Sub_type__c == 'Speaker', Interaction_Type__c = 'CDC_Interaction');

        insert intr;       
    }
}

 try this.

KevinRussellKevinRussell

Sill gives the "Field is not writable" message when I try to compile it...

Error: Compile Error: Field is not writeable: Interaction__c.Selected_Sub_type__c

 

@isTest
private class Contacts_Guest_Speaker_CheckboxTest
{
    static TestMethod void Test0_StatementTrue()
    {  
        Account acc = new Account(Name='TestAccount');
        insert acc;

        Contact con = new Contact(AccountId = acc.Id);
        insert con;

        Interaction__c intr = new Interaction__c(Account__c = acc.Id, Contact__c = con.Id, Selected_Sub_type__c = 'Speaker', Interaction_Type__c = 'CDC_Interaction');
        
        insert intr;       
    }
}

 

Naidu PothiniNaidu Pothini
@isTest
private class Contacts_Guest_Speaker_CheckboxTest
{
    static TestMethod void Test0_StatementTrue()
    {  
        Account acc = new Account(Name='TestAccount');
        insert acc;

        Contact con = new Contact(AccountId = acc.Id);
        insert con;

        Interaction__c intr = new Interaction__c(Account__c = acc.Id, Contact__c = con.Id, Interaction_Type__c = 'CDC_Interaction');

        insert intr;       
    }
}

 try this.

KevinRussellKevinRussell

Same deal. 

Error: Compile Error: Field is not writeable: Interaction__c.Interaction_Type__c at line 12 column 114

 

 

@isTest
private class Contacts_Guest_Speaker_CheckboxTest
{
    static TestMethod void Test0_StatementTrue()
    {  
        Account acc = new Account(Name='TestAccount');
        insert acc;

        Contact con = new Contact(AccountId = acc.Id);
        insert con;

        Interaction__c intr = new Interaction__c(Account__c = acc.Id, Contact__c = con.Id, Interaction_Type__c = 'CDC_Interaction');

        insert intr;       
    }
}

 

Naidu PothiniNaidu Pothini
@isTest
private class Contacts_Guest_Speaker_CheckboxTest
{
    public static String rectypeId1 = [SELECT Id, Name FROM RecordType WHERE Name = 'CDC_Interaction' AND SObjectType = 'Interaction__c'].Id;
    public static String rectypeId2 = [SELECT Id, Name FROM RecordType WHERE Name = 'Alumn_Interaction' AND SObjectType = 'Interaction__c'].Id;
    public static String rectypeId3 = [SELECT Id, Name FROM RecordType WHERE Name = 'ExecED' AND SObjectType = 'Interaction__c'].Id;

    static TestMethod void Test0_StatementTrue()
    {  
        Account acc = new Account(Name='TestAccount', --- required fields ----);
        insert acc;

        Contact con = new Contact(AccountId = acc.Id, --- required fields ----);
        insert con;

        List<Interaction__c> intList = new List<Interaction__c>();

        Interaction__c intr1 = new Interaction__c(Account__c = acc.Id, Contact__c = con.Id, RecordTypeId = recTypeId1);
        Interaction__c intr2 = new Interaction__c(Account__c = acc.Id, Contact__c = con.Id, RecordTypeId = recTypeId2);
        Interaction__c intr3 = new Interaction__c(Account__c = acc.Id, Contact__c = con.Id, RecordTypeId = recTypeId3);

        intList.add(intr1);
        intList.add(intr2);
        intList.add(intr3);

        insert intList;
    }
}

 

KevinRussellKevinRussell

Thanks NaiduPothini,  I'm getting closer, the code compiled, the test failed, but, this time it must be due to the required pick list field value:

  • Selected_Sub_type__c

This is a Interaction object pick list where the value would be set to 'Speaker'.  Is there an equivelent query I can use for picklists?

 

Pass/Fail Fail 
Error Message System.QueryException: List has no rows for assignment to SObject 
Stack Trace Class.Contacts_Guest_Speaker_CheckboxTest: line 5, column 1

 

 

 

Here is the saved/compiled code:

@isTest
private class Contacts_Guest_Speaker_CheckboxTest
{
    public static String rectypeId1 = [SELECT Id, Name FROM RecordType WHERE Name = 'CDC_Interaction' AND SObjectType = 'Interaction__c'].Id;
    public static String rectypeId2 = [SELECT Id, Name FROM RecordType WHERE Name = 'Alumn_Interaction' AND SObjectType = 'Interaction__c'].Id;
    public static String rectypeId3 = [SELECT Id, Name FROM RecordType WHERE Name = 'ExecED' AND SObjectType = 'Interaction__c'].Id;

    static TestMethod void Test0_StatementTrue()
    {  
        Account acc = new Account(Name='TestAccount');
        insert acc;

        Contact con = new Contact(AccountId = acc.Id);
        insert con;

        List<Interaction__c> intList = new List<Interaction__c>();

        Interaction__c intr1 = new Interaction__c(Account__c = acc.Id, Contact__c = con.Id, RecordTypeId = recTypeId1);
        Interaction__c intr2 = new Interaction__c(Account__c = acc.Id, Contact__c = con.Id, RecordTypeId = recTypeId2);
        Interaction__c intr3 = new Interaction__c(Account__c = acc.Id, Contact__c = con.Id, RecordTypeId = recTypeId3);

        intList.add(intr1);
        intList.add(intr2);
        intList.add(intr3);

        insert intList;
    }
}

 

Naidu PothiniNaidu Pothini
@isTest
private class Contacts_Guest_Speaker_CheckboxTest
{
    public static String rectypeId1 = [SELECT Id, Name FROM RecordType WHERE Name = 'CDC_Interaction' AND SObjectType = 'Interaction__c'].Id;
    public static String rectypeId2 = [SELECT Id, Name FROM RecordType WHERE Name = 'Alumn_Interaction' AND SObjectType = 'Interaction__c'].Id;
    public static String rectypeId3 = [SELECT Id, Name FROM RecordType WHERE Name = 'ExecED' AND SObjectType = 'Interaction__c'].Id;
    static TestMethod void Test0_StatementTrue()
    {  
        Account acc = new Account(Name='TestAccount');
        insert acc;

        Contact con = new Contact(AccountId = acc.Id);
        insert con;

        List<Interaction__c> intList = new List<Interaction__c>();

        Interaction__c intr1 = new Interaction__c(Account__c = acc.Id, Contact__c = con.Id, RecordTypeId = recTypeId1);
        Interaction__c intr2 = new Interaction__c(Account__c = acc.Id, Contact__c = con.Id, RecordTypeId = recTypeId2);
        Interaction__c intr3 = new Interaction__c(Account__c = acc.Id, Contact__c = con.Id, RecordTypeId = recTypeId3);

        intList.add(intr1);
        intList.add(intr2);
        intList.add(intr3);

        insert intList;
    }
}

 I guess you are getting the error message from the third query. can you check the recordtype name?

 

Can you post the debug log here?

KevinRussellKevinRussell

I think this is the log:

Let me know if there is a more detailed log I can retrieve.

 

(0/1) Test Methods Passed.

 

Apex Test Result Detail 

Time Started 3/26/2013 4:18 PM 
Class Contacts_Guest_Speaker_CheckboxTest 
Method Name Test0_StatementTrue 
Pass/Fail Fail 
Error Message System.QueryException: List has no rows for assignment to SObject 
Stack Trace Class.Contacts_Guest_Speaker_CheckboxTest: line 5, column 1 

 

KevinRussellKevinRussell
Record Type Names: Advancement Interaction, Alumn Interaction, CDC_Interaction, ExecEd Interaction.
on the Interaction object. I'll get the Pick List values.
KevinRussellKevinRussell
Pick List values:
CDC_Interaction: Posting, Company Briefing, Visit, Speaker, etc..... didn't think you needed all.

Field Name: Sub_type
API Name: Sub_type__c
Object Name: Interaction
Data Type: Picklist
KevinRussellKevinRussell
Record Type: CDC_Interaction
Record Type Name: CDC_Interaction
Naidu PothiniNaidu Pothini
@isTest
private class Contacts_Guest_Speaker_CheckboxTest
{
    public static String rectypeId1 = [SELECT Id, Name FROM RecordType WHERE Name = 'CDC_Interaction' AND SObjectType = 'Interaction__c'].Id;
    public static String rectypeId2 = [SELECT Id, Name FROM RecordType WHERE Name = 'Alumn_Interaction' AND SObjectType = 'Interaction__c'].Id;
    public static String rectypeId3 = [SELECT Id, Name FROM RecordType WHERE Name = 'ExecEd Interaction' AND SObjectType = 'Interaction__c'].Id;
    static TestMethod void Test0_StatementTrue()
    {  
        Account acc = new Account(Name='TestAccount');
        insert acc;

        Contact con = new Contact(AccountId = acc.Id);
        insert con;

        List<Interaction__c> intList = new List<Interaction__c>();

        Interaction__c intr1 = new Interaction__c(Account__c = acc.Id, Contact__c = con.Id, RecordTypeId = recTypeId1);
        Interaction__c intr2 = new Interaction__c(Account__c = acc.Id, Contact__c = con.Id, RecordTypeId = recTypeId2);
        Interaction__c intr3 = new Interaction__c(Account__c = acc.Id, Contact__c = con.Id, RecordTypeId = recTypeId3);

        intList.add(intr1);
        intList.add(intr2);
        intList.add(intr3);

        insert intList;
    }
}

 check the above record type names... if you could get the recordtypeIDs then i guess this would work.

Naidu PothiniNaidu Pothini

you can get more detailed logs from the log sheet in the debug logs.

 

Your Name > Setup > Administrative Setup > Monitoring > debug logs.

 

Click on new and add your user name so that you can see the debug logs generated...

KevinRussellKevinRussell

NaiduPothini, I finally saw what you needed me to check on.  I ended up deleting the 3rd row because I kept getting errors on it.  I could not exactly identify why that record was failing.  Now I'm hoping the issue is the sub_type pick list....

 

Here is the current test code:

@isTest
private class Contacts_Guest_Speaker_CheckboxTest
{
    public static String rectypeId1 = [SELECT Id, Name FROM RecordType WHERE Name = 'CDC_Interaction' AND SObjectType = 'Interaction__c'].Id;
    public static String rectypeId2 = [SELECT Id, Name FROM RecordType WHERE Name = 'Alumn Interaction' AND SObjectType = 'Interaction__c'].Id;

    static TestMethod void Test0_StatementTrue()
    {  
        Account acc = new Account(Name='TestAccount');
        insert acc;

        Contact con = new Contact(AccountId = acc.Id);
        insert con;

        List<Interaction__c> intList = new List<Interaction__c>();

        Interaction__c intr1 = new Interaction__c(Account__c = acc.Id, Contact__c = con.Id, RecordTypeId = recTypeId1);
        Interaction__c intr2 = new Interaction__c(Account__c = acc.Id, Contact__c = con.Id, RecordTypeId = recTypeId2);

        intList.add(intr1);
        intList.add(intr2);

        insert intList;
    }
}

 Here is the log from the test:

User Kevin Russell Date 3/26/2013 5:05:54 PM EDT 

Status Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [LastName]: [LastName] Application Unknown 
Request Type Api Operation ApexTestHandler 
Duration (ms) 3,267 Log Size (bytes) 9,752 

Log 27.0 APEX_CODE,DEBUG;APEX_PROFILING,INFO;CALLOUT,INFO;DB,INFO;SYSTEM,DEBUG;VALIDATION,INFO;VISUALFORCE,INFO;WORKFLOW,INFO
17:05:53.256 (1256877000)|EXECUTION_STARTED
17:05:53.256 (1256935000)|CODE_UNIT_STARTED|[EXTERNAL]|01pJ00000009WAc|Contacts_Guest_Speaker_CheckboxTest.Test0_StatementTrue
17:05:53.258 (1258470000)|METHOD_ENTRY|[2]|01pJ00000009WAc|Contacts_Guest_Speaker_CheckboxTest.Contacts_Guest_Speaker_CheckboxTest()
17:05:53.259 (1259030000)|SOQL_EXECUTE_BEGIN|[4]|Aggregations:0|select Id, Name from RecordType where (Name = 'CDC_Interaction' and SObjectType = 'Interaction__c')
17:05:53.269 (1269746000)|SOQL_EXECUTE_END|[4]|Rows:1
17:05:53.270 (1270358000)|SOQL_EXECUTE_BEGIN|[5]|Aggregations:0|select Id, Name from RecordType where (Name = 'Alumn Interaction' and SObjectType = 'Interaction__c')
17:05:53.272 (1272071000)|SOQL_EXECUTE_END|[5]|Rows:1
17:05:53.272 (1272169000)|METHOD_EXIT|[2]|Contacts_Guest_Speaker_CheckboxTest
17:05:53.275 (1275293000)|DML_BEGIN|[10]|Op:Insert|Type:Account|Rows:1
17:05:53.460 (1460421000)|ENTERING_MANAGED_PKG|SFSSDupeCatcher
17:05:53.669 (1669018000)|SOQL_EXECUTE_BEGIN|[50]|Aggregations:0|select Id, Name, SFSSDupeCatcher__Match_On_Insert_Action__c, SFSSDupeCatcher__Match_On_Update_Action__c, SFSSDupeCatcher__Create_Tasks_for_Warnings__c, SFSSDupeCatcher__Blocked_Duplicates__c, SFSSDupeCatcher__Merged_Duplicates__c, SFSSDupeCatcher__Converted_Duplicates__c, SFSSDupeCatcher__Error_Message__c, SFSSDupeCatcher__Scenario_Type__c, SFSSDupeCatcher__Deployed__c, SFSSDupeCatcher__Bypass_Security__c, SFSSDupeCatcher__Person_Account_Filter__c, OwnerID, CreatedById from Scenario__c where (Deployed__c = true and Match_On_Insert_Action__c != 'Report Duplicate') limit 100
17:05:53.676 (1676497000)|SOQL_EXECUTE_END|[50]|Rows:0
17:05:53.699 (1699888000)|CODE_UNIT_STARTED|[EXTERNAL]|Validation:Account:new
17:05:53.699 (1699908000)|VALIDATION_RULE|03dd0000000bcpi|Block_autoupdate_from_Data_com
17:05:53.710 (1710998000)|VALIDATION_FORMULA|(  jsImpacts__Data_com_does_not_auto_update__c  ) && ($User.Alias = "autocln") && (ISCHANGED(  DunsNumber  )  &#124;&#124;  ISCHANGED(   NumberOfEmployees   ) &#124;&#124;  ISCHANGED(    AnnualRevenue    ) &#124;&#124;  ISCHANGED(  TickerSymbol  ) &#124;&#124;  ISCHANGED(  Website  ) &#124;&#124;  ISCHANGED(  Industry  ) &#124;&#124;  ISCHANGED(   Ownership   ) &#124;&#124;  ISCHANGED(   BillingCity   ) &#124;&#124;  ISCHANGED(   BillingCountry   ) &#124;&#124;  ISCHANGED(   BillingState   ) &#124;&#124;  ISCHANGED(   BillingStreet   ) &#124;&#124;  ISCHANGED(   BillingPostalCode   ) &#124;&#124;  ISCHANGED(   Phone   ) &#124;&#124;  ISCHANGED(   Fax   ) &#124;&#124;  ISCHANGED(  Site   ) &#124;&#124;  ISCHANGED(  Tradestyle   ) &#124;&#124;  ISCHANGED(   YearStarted   ) &#124;&#124;  ISCHANGED(   Sic   ) &#124;&#124;  ISCHANGED(   SicDesc   ) &#124;&#124;  ISCHANGED(   NaicsCode   ) &#124;&#124;  ISCHANGED(   NaicsDesc   ) &#124;&#124;  ISCHANGED(   Description   ) )|SicDesc=null , NaicsCode=null , DunsNumber=null , Description=null , Phone=null , BillingCountry=null , Site=null , TickerSymbol=null , $User.Alias=kruss , Tradestyle=null , Website=null , Fax=null , YearStarted=null , BillingStreet=null , AnnualRevenue=null , BillingState=null , NumberOfEmployees=null , jsImpacts__Data_com_does_not_auto_update__c=0 , BillingCity=null , BillingPostalCode=null , NaicsDesc=null , Sic=null , Ownership=null , Industry=null
17:05:53.711 (1711043000)|VALIDATION_PASS
17:05:53.711 (1711049000)|CODE_UNIT_FINISHED|Validation:Account:new
17:05:54.560 (2560129000)|ENTERING_MANAGED_PKG|SFSSDupeCatcher
17:05:54.563 (2563856000)|SOQL_EXECUTE_BEGIN|[105]|Aggregations:0|select Id, Name, SFSSDupeCatcher__Match_On_Insert_Action__c, SFSSDupeCatcher__Match_On_Update_Action__c, SFSSDupeCatcher__Create_Tasks_for_Warnings__c, SFSSDupeCatcher__Blocked_Duplicates__c, SFSSDupeCatcher__Merged_Duplicates__c, SFSSDupeCatcher__Converted_Duplicates__c, SFSSDupeCatcher__Error_Message__c, SFSSDupeCatcher__Scenario_Type__c, SFSSDupeCatcher__Deployed__c, SFSSDupeCatcher__Bypass_Security__c, SFSSDupeCatcher__Person_Account_Filter__c, OwnerID, CreatedById from Scenario__c where Deployed__c = true limit 100
17:05:54.566 (2566738000)|SOQL_EXECUTE_END|[105]|Rows:0
17:05:54.843 (2843558000)|ENTERING_MANAGED_PKG|rhx
17:05:54.858 (2858452000)|DML_END|[10]
17:05:54.859 (2859045000)|DML_BEGIN|[13]|Op:Insert|Type:Contact|Rows:1
17:05:54.884 (2884314000)|ENTERING_MANAGED_PKG|SFSSDupeCatcher
17:05:54.961 (2961722000)|SOQL_EXECUTE_BEGIN|[50]|Aggregations:0|select Id, Name, SFSSDupeCatcher__Match_On_Insert_Action__c, SFSSDupeCatcher__Match_On_Update_Action__c, SFSSDupeCatcher__Create_Tasks_for_Warnings__c, SFSSDupeCatcher__Blocked_Duplicates__c, SFSSDupeCatcher__Merged_Duplicates__c, SFSSDupeCatcher__Converted_Duplicates__c, SFSSDupeCatcher__Error_Message__c, SFSSDupeCatcher__Scenario_Type__c, SFSSDupeCatcher__Deployed__c, SFSSDupeCatcher__Bypass_Security__c, SFSSDupeCatcher__Person_Account_Filter__c, OwnerID, CreatedById from Scenario__c where (Deployed__c = true and Match_On_Insert_Action__c != 'Report Duplicate') limit 100
17:05:54.964 (2964590000)|SOQL_EXECUTE_END|[50]|Rows:0
17:05:54.968 (2968260000)|ENTERING_MANAGED_PKG|npe5
17:05:54.974 (2974933000)|CODE_UNIT_STARTED|[EXTERNAL]|Validation:Contact:new
17:05:54.974 (2974952000)|VALIDATION_RULE|03dd0000000bcpj|Block_autoupdate_from_Data_com
17:05:54.975 (2975343000)|VALIDATION_FORMULA|(  jsImpacts__Data_com_does_not_auto_update__c  ) && ($User.Alias = "autocln") && (ISCHANGED(  Title  ) &#124;&#124; ISCHANGED(  Email  ) &#124;&#124; ISCHANGED(  Phone  ) &#124;&#124; ISCHANGED(  MailingStreet  ) &#124;&#124; ISCHANGED(  MailingCity  ) &#124;&#124; ISCHANGED(  MailingState  ) &#124;&#124; ISCHANGED(  MailingCountry  ) &#124;&#124; ISCHANGED(  MailingPostalCode  ) )|jsImpacts__Data_com_does_not_auto_update__c=0 , MailingState=null , Phone=null , MailingCity=null , Email=null , $User.Alias=kruss , MailingStreet=null , MailingCountry=null , MailingPostalCode=null , Title=null
17:05:54.975 (2975370000)|VALIDATION_PASS
17:05:54.975 (2975375000)|CODE_UNIT_FINISHED|Validation:Contact:new
17:05:54.976 (2976764000)|DML_END|[13]
17:05:54.976 (2976926000)|VF_PAGE_MESSAGE|Required fields are missing: [LastName]
17:05:54.977 (2977034000)|EXCEPTION_THROWN|[13]|System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [LastName]: [LastName]
17:05:54.977 (2977921000)|FATAL_ERROR|System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [LastName]: [LastName]

Class.Contacts_Guest_Speaker_CheckboxTest.Test0_StatementTrue: line 13, column 1
17:05:54.977 (2977943000)|FATAL_ERROR|System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [LastName]: [LastName]

Class.Contacts_Guest_Speaker_CheckboxTest.Test0_StatementTrue: line 13, column 1
17:05:54.086 (2977968000)|CUMULATIVE_LIMIT_USAGE
17:05:54.086|LIMIT_USAGE_FOR_NS|(default)|
  Number of SOQL queries: 2 out of 100
  Number of query rows: 2 out of 50000
  Number of SOSL queries: 0 out of 20
  Number of DML statements: 2 out of 150
  Number of DML rows: 2 out of 10000
  Number of code statements: 6 out of 200000
  Maximum heap size: 0 out of 6000000
  Number of callouts: 0 out of 10
  Number of Email Invocations: 0 out of 10
  Number of fields describes: 0 out of 100
  Number of record type describes: 0 out of 100
  Number of child relationships describes: 0 out of 100
  Number of picklist describes: 0 out of 100
  Number of future calls: 0 out of 10

17:05:54.086|LIMIT_USAGE_FOR_NS|rh2|
  Number of SOQL queries: 0 out of 100
  Number of query rows: 0 out of 50000
  Number of SOSL queries: 0 out of 20
  Number of DML statements: 0 out of 150
  Number of DML rows: 0 out of 10000
  Number of code statements: 10 out of 200000
  Maximum heap size: 0 out of 6000000
  Number of callouts: 0 out of 10
  Number of Email Invocations: 0 out of 10
  Number of fields describes: 0 out of 100
  Number of record type describes: 0 out of 100
  Number of child relationships describes: 0 out of 100
  Number of picklist describes: 0 out of 100
  Number of future calls: 0 out of 10

17:05:54.086|LIMIT_USAGE_FOR_NS|rhx|
  Number of SOQL queries: 0 out of 100
  Number of query rows: 0 out of 50000
  Number of SOSL queries: 0 out of 20
  Number of DML statements: 0 out of 150
  Number of DML rows: 0 out of 10000
  Number of code statements: 5 out of 200000
  Maximum heap size: 0 out of 6000000
  Number of callouts: 0 out of 10
  Number of Email Invocations: 0 out of 10
  Number of fields describes: 0 out of 100
  Number of record type describes: 0 out of 100
  Number of child relationships describes: 0 out of 100
  Number of picklist describes: 0 out of 100
  Number of future calls: 0 out of 10

17:05:54.086|LIMIT_USAGE_FOR_NS|SFSSDupeCatcher|
  Number of SOQL queries: 2 out of 100
  Number of query rows: 0 out of 50000
  Number of SOSL queries: 0 out of 20
  Number of DML statements: 0 out of 150
  Number of DML rows: 0 out of 10000
  Number of code statements: 308 out of 200000
  Maximum heap size: 0 out of 6000000
  Number of callouts: 0 out of 10
  Number of Email Invocations: 0 out of 10
  Number of fields describes: 0 out of 100
  Number of record type describes: 0 out of 100
  Number of child relationships describes: 0 out of 100
  Number of picklist describes: 0 out of 100
  Number of future calls: 0 out of 10

17:05:54.086|CUMULATIVE_LIMIT_USAGE_END

17:05:54.978 (2978045000)|CODE_UNIT_FINISHED|Contacts_Guest_Speaker_CheckboxTest.Test0_StatementTrue
17:05:54.978 (2978052000)|EXECUTION_FINISHED

     


  

 

 

Naidu PothiniNaidu Pothini
@isTest
private class Contacts_Guest_Speaker_CheckboxTest
{
    public static String rectypeId1 = [SELECT Id, Name FROM RecordType WHERE Name = 'CDC_Interaction' AND SObjectType = 'Interaction__c'].Id;
    public static String rectypeId2 = [SELECT Id, Name FROM RecordType WHERE Name = 'Alumn Interaction' AND SObjectType = 'Interaction__c'].Id;

    static TestMethod void Test0_StatementTrue()
    {  
        Account acc = new Account(Name='TestAccount');
        insert acc;

        Contact con = new Contact(AccountId = acc.Id, lastName = 'TestLastName');
        insert con;

        List<Interaction__c> intList = new List<Interaction__c>();

        Interaction__c intr1 = new Interaction__c(Account__c = acc.Id, Contact__c = con.Id, RecordTypeId = recTypeId1);
        Interaction__c intr2 = new Interaction__c(Account__c = acc.Id, Contact__c = con.Id, RecordTypeId = recTypeId2);

        intList.add(intr1);
        intList.add(intr2);

        insert intList;
    }
}

 

User Kevin Russell Date 3/26/2013 5:05:54 PM EDT 

Status Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [LastName]: [LastName] Application Unknown 
Request Type Api Operation ApexTestHandler 
Duration (ms) 3,267 Log Size (bytes) 9,752 

Log 27.0 APEX_CODE,DEBUG;APEX_PROFILING,INFO;CALLOUT,INFO;DB,INFO;SYSTEM,DEBUG;VALIDATION,INFO;VISUALFORCE,INFO;WORKFLOW,INFO
17:05:53.256 (1256877000)|EXECUTION_STARTED
17:05:53.256 (1256935000)|CODE_UNIT_STARTED|[EXTERNAL]|01pJ00000009WAc|Contacts_Guest_Speaker_CheckboxTest.Test0_StatementTrue
17:05:53.258 (1258470000)|METHOD_ENTRY|[2]|01pJ00000009WAc|Contacts_Guest_Speaker_CheckboxTest.Contacts_Guest_Speaker_CheckboxTest()
17:05:53.259 (1259030000)|SOQL_EXECUTE_BEGIN|[4]|Aggregations:0|select Id, Name from RecordType where (Name = 'CDC_Interaction' and SObjectType = 'Interaction__c')
17:05:53.269 (1269746000)|SOQL_EXECUTE_END|[4]|Rows:1
17:05:53.270 (1270358000)|SOQL_EXECUTE_BEGIN|[5]|Aggregations:0|select Id, Name from RecordType where (Name = 'Alumn Interaction' and SObjectType = 'Interaction__c')
17:05:53.272 (1272071000)|SOQL_EXECUTE_END|[5]|Rows:1
17:05:53.272 (1272169000)|METHOD_EXIT|[2]|Contacts_Guest_Speaker_CheckboxTest
17:05:53.275 (1275293000)|DML_BEGIN|[10]|Op:Insert|Type:Account|Rows:1
17:05:53.460 (1460421000)|ENTERING_MANAGED_PKG|SFSSDupeCatcher
17:05:53.669 (1669018000)|SOQL_EXECUTE_BEGIN|[50]|Aggregations:0|select Id, Name, SFSSDupeCatcher__Match_On_Insert_Action__c, SFSSDupeCatcher__Match_On_Update_Action__c, SFSSDupeCatcher__Create_Tasks_for_Warnings__c, SFSSDupeCatcher__Blocked_Duplicates__c, SFSSDupeCatcher__Merged_Duplicates__c, SFSSDupeCatcher__Converted_Duplicates__c, SFSSDupeCatcher__Error_Message__c, SFSSDupeCatcher__Scenario_Type__c, SFSSDupeCatcher__Deployed__c, SFSSDupeCatcher__Bypass_Security__c, SFSSDupeCatcher__Person_Account_Filter__c, OwnerID, CreatedById from Scenario__c where (Deployed__c = true and Match_On_Insert_Action__c != 'Report Duplicate') limit 100
17:05:53.676 (1676497000)|SOQL_EXECUTE_END|[50]|Rows:0
17:05:53.699 (1699888000)|CODE_UNIT_STARTED|[EXTERNAL]|Validation:Account:new
17:05:53.699 (1699908000)|VALIDATION_RULE|03dd0000000bcpi|Block_autoupdate_from_Data_com
17:05:53.710 (1710998000)|VALIDATION_FORMULA|(  jsImpacts__Data_com_does_not_auto_update__c  ) && ($User.Alias = "autocln") && (ISCHANGED(  DunsNumber  )  &#124;&#124;  ISCHANGED(   NumberOfEmployees   ) &#124;&#124;  ISCHANGED(    AnnualRevenue    ) &#124;&#124;  ISCHANGED(  TickerSymbol  ) &#124;&#124;  ISCHANGED(  Website  ) &#124;&#124;  ISCHANGED(  Industry  ) &#124;&#124;  ISCHANGED(   Ownership   ) &#124;&#124;  ISCHANGED(   BillingCity   ) &#124;&#124;  ISCHANGED(   BillingCountry   ) &#124;&#124;  ISCHANGED(   BillingState   ) &#124;&#124;  ISCHANGED(   BillingStreet   ) &#124;&#124;  ISCHANGED(   BillingPostalCode   ) &#124;&#124;  ISCHANGED(   Phone   ) &#124;&#124;  ISCHANGED(   Fax   ) &#124;&#124;  ISCHANGED(  Site   ) &#124;&#124;  ISCHANGED(  Tradestyle   ) &#124;&#124;  ISCHANGED(   YearStarted   ) &#124;&#124;  ISCHANGED(   Sic   ) &#124;&#124;  ISCHANGED(   SicDesc   ) &#124;&#124;  ISCHANGED(   NaicsCode   ) &#124;&#124;  ISCHANGED(   NaicsDesc   ) &#124;&#124;  ISCHANGED(   Description   ) )|SicDesc=null , NaicsCode=null , DunsNumber=null , Description=null , Phone=null , BillingCountry=null , Site=null , TickerSymbol=null , $User.Alias=kruss , Tradestyle=null , Website=null , Fax=null , YearStarted=null , BillingStreet=null , AnnualRevenue=null , BillingState=null , NumberOfEmployees=null , jsImpacts__Data_com_does_not_auto_update__c=0 , BillingCity=null , BillingPostalCode=null , NaicsDesc=null , Sic=null , Ownership=null , Industry=null
17:05:53.711 (1711043000)|VALIDATION_PASS
17:05:53.711 (1711049000)|CODE_UNIT_FINISHED|Validation:Account:new
17:05:54.560 (2560129000)|ENTERING_MANAGED_PKG|SFSSDupeCatcher
17:05:54.563 (2563856000)|SOQL_EXECUTE_BEGIN|[105]|Aggregations:0|select Id, Name, SFSSDupeCatcher__Match_On_Insert_Action__c, SFSSDupeCatcher__Match_On_Update_Action__c, SFSSDupeCatcher__Create_Tasks_for_Warnings__c, SFSSDupeCatcher__Blocked_Duplicates__c, SFSSDupeCatcher__Merged_Duplicates__c, SFSSDupeCatcher__Converted_Duplicates__c, SFSSDupeCatcher__Error_Message__c, SFSSDupeCatcher__Scenario_Type__c, SFSSDupeCatcher__Deployed__c, SFSSDupeCatcher__Bypass_Security__c, SFSSDupeCatcher__Person_Account_Filter__c, OwnerID, CreatedById from Scenario__c where Deployed__c = true limit 100
17:05:54.566 (2566738000)|SOQL_EXECUTE_END|[105]|Rows:0
17:05:54.843 (2843558000)|ENTERING_MANAGED_PKG|rhx
17:05:54.858 (2858452000)|DML_END|[10]
17:05:54.859 (2859045000)|DML_BEGIN|[13]|Op:Insert|Type:Contact|Rows:1
17:05:54.884 (2884314000)|ENTERING_MANAGED_PKG|SFSSDupeCatcher
17:05:54.961 (2961722000)|SOQL_EXECUTE_BEGIN|[50]|Aggregations:0|select Id, Name, SFSSDupeCatcher__Match_On_Insert_Action__c, SFSSDupeCatcher__Match_On_Update_Action__c, SFSSDupeCatcher__Create_Tasks_for_Warnings__c, SFSSDupeCatcher__Blocked_Duplicates__c, SFSSDupeCatcher__Merged_Duplicates__c, SFSSDupeCatcher__Converted_Duplicates__c, SFSSDupeCatcher__Error_Message__c, SFSSDupeCatcher__Scenario_Type__c, SFSSDupeCatcher__Deployed__c, SFSSDupeCatcher__Bypass_Security__c, SFSSDupeCatcher__Person_Account_Filter__c, OwnerID, CreatedById from Scenario__c where (Deployed__c = true and Match_On_Insert_Action__c != 'Report Duplicate') limit 100
17:05:54.964 (2964590000)|SOQL_EXECUTE_END|[50]|Rows:0
17:05:54.968 (2968260000)|ENTERING_MANAGED_PKG|npe5
17:05:54.974 (2974933000)|CODE_UNIT_STARTED|[EXTERNAL]|Validation:Contact:new
17:05:54.974 (2974952000)|VALIDATION_RULE|03dd0000000bcpj|Block_autoupdate_from_Data_com
17:05:54.975 (2975343000)|VALIDATION_FORMULA|(  jsImpacts__Data_com_does_not_auto_update__c  ) && ($User.Alias = "autocln") && (ISCHANGED(  Title  ) &#124;&#124; ISCHANGED(  Email  ) &#124;&#124; ISCHANGED(  Phone  ) &#124;&#124; ISCHANGED(  MailingStreet  ) &#124;&#124; ISCHANGED(  MailingCity  ) &#124;&#124; ISCHANGED(  MailingState  ) &#124;&#124; ISCHANGED(  MailingCountry  ) &#124;&#124; ISCHANGED(  MailingPostalCode  ) )|jsImpacts__Data_com_does_not_auto_update__c=0 , MailingState=null , Phone=null , MailingCity=null , Email=null , $User.Alias=kruss , MailingStreet=null , MailingCountry=null , MailingPostalCode=null , Title=null
17:05:54.975 (2975370000)|VALIDATION_PASS
17:05:54.975 (2975375000)|CODE_UNIT_FINISHED|Validation:Contact:new
17:05:54.976 (2976764000)|DML_END|[13]
17:05:54.976 (2976926000)|VF_PAGE_MESSAGE|Required fields are missing: [LastName]
17:05:54.977 (2977034000)|EXCEPTION_THROWN|[13]|System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [LastName]: [LastName]
17:05:54.977 (2977921000)|FATAL_ERROR|System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [LastName]: [LastName]

Class.Contacts_Guest_Speaker_CheckboxTest.Test0_StatementTrue: line 13, column 1
17:05:54.977 (2977943000)|FATAL_ERROR|System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [LastName]: [LastName]

Class.Contacts_Guest_Speaker_CheckboxTest.Test0_StatementTrue: line 13, column 1
17:05:54.086 (2977968000)|CUMULATIVE_LIMIT_USAGE
17:05:54.086|LIMIT_USAGE_FOR_NS|(default)|

 

KevinRussellKevinRussell

Hi NaiduPothini and sfdcfox,

 

Thank you both very, very,very much!

 

The test for this trigger finally passed.  I have a lot to learn....

 

Here is the test code as it is now, before I tweak anything else:

@isTest
private class Contacts_Guest_Speaker_CheckboxTest
{
    public static String rectypeId1 = [SELECT Id, Name FROM RecordType WHERE Name = 'CDC_Interaction' AND SObjectType = 'Interaction__c'].Id;
    public static String rectypeId2 = [SELECT Id, Name FROM RecordType WHERE Name = 'Alumn Interaction' AND SObjectType = 'Interaction__c'].Id;
    public static String rectypeId3 = [SELECT Id, Name FROM RecordType WHERE Name = 'ExecEd Interaction' AND SObjectType = 'Interaction__c'].Id;    

    static TestMethod void Test0_StatementTrue()
    {  
        Account acc = new Account(Name='TestAccount');
        insert acc;

        Contact con = new Contact(AccountId = acc.Id, lastName = 'TestLastName');
        insert con;

        List<Interaction__c> intList = new List<Interaction__c>();

        Interaction__c intr1 = new Interaction__c(Account__c = acc.Id, Contact__c = con.Id, RecordTypeId = recTypeId1);
        Interaction__c intr2 = new Interaction__c(Account__c = acc.Id, Contact__c = con.Id, RecordTypeId = recTypeId2);
        Interaction__c intr3 = new Interaction__c(Account__c = acc.Id, Contact__c = con.Id, RecordTypeId = recTypeId3);        

        intList.add(intr1);
        intList.add(intr2);
        intList.add(intr3);        

        insert intList;
    }
}

 

This was selected as the best answer